Skip to content

Commit f5d8b19

Browse files
committed
Use more numeric stuff
1 parent 907f454 commit f5d8b19

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/ZMidi/Internal/ParserMonad.fs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module ParserMonad =
66
open System.IO
77
open FSharpPlus
88
open FSharpPlus.Data
9+
open FSharpPlus.Math.Generic
910

1011
/// Status is either OFF or the previous VoiceEvent * Channel.
1112
type VoiceEvent =
@@ -68,6 +69,8 @@ module ParserMonad =
6869
#if DEBUG_LASTPARSE
6970
* lastToken : obj // need top level type, picking System.Object for now
7071
#endif
72+
with
73+
static member (+) (_: ParseError, y: ParseError) = y
7174

7275
let inline mkOtherParseError st (genMessage : Pos -> string) =
7376
ParseError(
@@ -134,11 +137,7 @@ module ParserMonad =
134137
let mzero () : ParserMonad<'a> =
135138
StateT <| fun state -> Error (mkParseError state (EOF "mzero"))
136139

137-
let inline mplus (parser1 : ParserMonad<'a>) (parser2 : ParserMonad<'a>) : ParserMonad<'a> =
138-
StateT <| fun state ->
139-
match apply1 parser1 state with
140-
| Error _ -> apply1 parser2 state
141-
| Ok res -> Ok res
140+
let inline mplus (parser1 : ParserMonad<'a>) (parser2 : ParserMonad<'a>) : ParserMonad<'a> = parser1 <|> parser2
142141

143142
let inline mfor (items: #seq<'a>) (fn: 'a -> ParserMonad<'b>) : ParserMonad<seq<'b>> = failwithf ""
144143

@@ -253,13 +252,13 @@ module ParserMonad =
253252
(st : State)
254253
(fk : ParseError -> Result<'a list * State, ParseError>)
255254
(sk : State -> 'a list -> Result<'a list * State, ParseError>) =
256-
if i <= LanguagePrimitives.GenericZero then
255+
if i <= 0G then
257256
sk st []
258257
else
259258
match apply1 parser st with
260259
| Error msg -> fk msg
261260
| Ok (a1, st1) ->
262-
work (i - LanguagePrimitives.GenericOne) st1 fk (fun st2 ac ->
261+
work (i - 1G) st1 fk (fun st2 ac ->
263262
sk st2 (a1 :: ac))
264263
work length state (fun msg -> Error msg) (fun st ac -> Ok (ac, st))
265264
|> Result.map (fun (ans, st) -> (List.toArray ans, st))

0 commit comments

Comments
 (0)