mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-29 04:04:02 +03:00
king: simplify parser types to avoid invalid existential newtype
This commit is contained in:
parent
2b74a8edd6
commit
74db584ad7
@ -12,10 +12,9 @@ module Urbit.Noun.Convert
|
||||
|
||||
import ClassyPrelude hiding (hash)
|
||||
|
||||
import Control.Monad.Fail (MonadFail (fail))
|
||||
import Urbit.Noun.Core
|
||||
|
||||
import qualified Control.Monad.Fail as Fail
|
||||
|
||||
|
||||
-- Types -----------------------------------------------------------------------
|
||||
|
||||
@ -24,11 +23,11 @@ type ParseStack = [Text]
|
||||
|
||||
-- "Parser" --------------------------------------------------------------------
|
||||
|
||||
type Failure f r = ParseStack -> String -> f r
|
||||
type Success a f r = a -> f r
|
||||
type Failure a = ParseStack -> String -> a
|
||||
type Success a b = a -> b
|
||||
|
||||
newtype Parser a = Parser {
|
||||
runParser :: forall f r. ParseStack -> Failure f r -> Success a f r -> f r
|
||||
runParser :: forall r. ParseStack -> Failure r -> Success a r -> r
|
||||
}
|
||||
|
||||
named :: Text -> Parser a -> Parser a
|
||||
@ -39,9 +38,8 @@ instance Monad Parser where
|
||||
m >>= g = Parser $ \path kf ks -> let ks' a = runParser (g a) path kf ks
|
||||
in runParser m path kf ks'
|
||||
return = pure
|
||||
fail = Fail.fail
|
||||
|
||||
instance Fail.MonadFail Parser where
|
||||
instance MonadFail Parser where
|
||||
fail msg = Parser $ \path kf _ks -> kf (reverse path) msg
|
||||
|
||||
instance Functor Parser where
|
||||
|
Loading…
Reference in New Issue
Block a user