Skip to content

Commit 64c1106

Browse files
committed
Use more numeric stuff
1 parent 24506f6 commit 64c1106

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/ZMidi/Internal/ParserMonad.fs

Lines changed: 8 additions & 9 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

@@ -243,13 +242,13 @@ module ParserMonad =
243242
(st : State)
244243
(fk : ParseError -> Result<'a list * State, ParseError>)
245244
(sk : State -> 'a list -> Result<'a list * State, ParseError>) =
246-
if i <= LanguagePrimitives.GenericZero then
245+
if i <= 0G then
247246
sk st []
248247
else
249248
match apply1 parser st with
250249
| Error msg -> fk msg
251250
| Ok (a1, st1) ->
252-
work (i - LanguagePrimitives.GenericOne) st1 fk (fun st2 ac ->
251+
work (i - 1G) st1 fk (fun st2 ac ->
253252
sk st2 (a1 :: ac))
254253
work length state (fun msg -> Error msg) (fun st ac -> Ok (ac, st))
255254
|> Result.map (fun (ans, st) -> (List.toArray ans, st))
@@ -285,7 +284,7 @@ module ParserMonad =
285284
let mutable lastState = state
286285
// revisit with a fold?
287286
let mutable error = Ok (Unchecked.defaultof<_>,lastState)
288-
let mutable i = LanguagePrimitives.GenericZero
287+
let mutable i = 0G
289288
let mutable errorOccured = false
290289
logf "bound repeat %i" n
291290

@@ -299,7 +298,7 @@ module ParserMonad =
299298
| (Error e) ->
300299
error <- Error e
301300
errorOccured <- true
302-
i <- i + LanguagePrimitives.GenericOne
301+
i <- i + 1G
303302
if errorOccured then
304303
error
305304
else

0 commit comments

Comments
 (0)