{-# LANGUAGE OverloadedStrings #-}
module Sugar.Data
  ( Type(..)
  , TypeRef(..)
  , Ty(..)
  , Rec(..)
  , Mem(..)
  , Adt(..)
  , Cons(..)
  , ConsValue(..)
  , Err(..)
  , Error(..)
  , ParamFns(..)
  , tokenToTypes
  , tokenToType
  ) where

import qualified Data.Text as T
import Data.Text (Text)
import Sugar

data Type a m c
  = Type'Ty (Ty a)
  | Type'Rec (Rec a m)
  | Type'Adt (Adt a m c)
  deriving (Int -> Type a m c -> ShowS
[Type a m c] -> ShowS
Type a m c -> String
(Int -> Type a m c -> ShowS)
-> (Type a m c -> String)
-> ([Type a m c] -> ShowS)
-> Show (Type a m c)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a m c.
(Show a, Show m, Show c) =>
Int -> Type a m c -> ShowS
forall a m c. (Show a, Show m, Show c) => [Type a m c] -> ShowS
forall a m c. (Show a, Show m, Show c) => Type a m c -> String
showList :: [Type a m c] -> ShowS
$cshowList :: forall a m c. (Show a, Show m, Show c) => [Type a m c] -> ShowS
show :: Type a m c -> String
$cshow :: forall a m c. (Show a, Show m, Show c) => Type a m c -> String
showsPrec :: Int -> Type a m c -> ShowS
$cshowsPrec :: forall a m c.
(Show a, Show m, Show c) =>
Int -> Type a m c -> ShowS
Show, Type a m c -> Type a m c -> Bool
(Type a m c -> Type a m c -> Bool)
-> (Type a m c -> Type a m c -> Bool) -> Eq (Type a m c)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a m c.
(Eq a, Eq m, Eq c) =>
Type a m c -> Type a m c -> Bool
/= :: Type a m c -> Type a m c -> Bool
$c/= :: forall a m c.
(Eq a, Eq m, Eq c) =>
Type a m c -> Type a m c -> Bool
== :: Type a m c -> Type a m c -> Bool
$c== :: forall a m c.
(Eq a, Eq m, Eq c) =>
Type a m c -> Type a m c -> Bool
Eq)

data TypeRef = TypeRef
  { TypeRef -> Text
trName :: Text
  , TypeRef -> [TypeRef]
trParams :: [TypeRef]
  , TypeRef -> SourceLocation
trLoc :: SourceLocation
  } deriving (Int -> TypeRef -> ShowS
[TypeRef] -> ShowS
TypeRef -> String
(Int -> TypeRef -> ShowS)
-> (TypeRef -> String) -> ([TypeRef] -> ShowS) -> Show TypeRef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypeRef] -> ShowS
$cshowList :: [TypeRef] -> ShowS
show :: TypeRef -> String
$cshow :: TypeRef -> String
showsPrec :: Int -> TypeRef -> ShowS
$cshowsPrec :: Int -> TypeRef -> ShowS
Show, TypeRef -> TypeRef -> Bool
(TypeRef -> TypeRef -> Bool)
-> (TypeRef -> TypeRef -> Bool) -> Eq TypeRef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TypeRef -> TypeRef -> Bool
$c/= :: TypeRef -> TypeRef -> Bool
== :: TypeRef -> TypeRef -> Bool
$c== :: TypeRef -> TypeRef -> Bool
Eq)

data Ty a = Ty
  { Ty a -> Text
tyName :: Text
  , Ty a -> Maybe a
tyParam :: Maybe a
  , Ty a -> TypeRef
tyType :: TypeRef
  , Ty a -> SourceLocation
tyLoc :: SourceLocation
  } deriving (Int -> Ty a -> ShowS
[Ty a] -> ShowS
Ty a -> String
(Int -> Ty a -> ShowS)
-> (Ty a -> String) -> ([Ty a] -> ShowS) -> Show (Ty a)
forall a. Show a => Int -> Ty a -> ShowS
forall a. Show a => [Ty a] -> ShowS
forall a. Show a => Ty a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ty a] -> ShowS
$cshowList :: forall a. Show a => [Ty a] -> ShowS
show :: Ty a -> String
$cshow :: forall a. Show a => Ty a -> String
showsPrec :: Int -> Ty a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Ty a -> ShowS
Show, Ty a -> Ty a -> Bool
(Ty a -> Ty a -> Bool) -> (Ty a -> Ty a -> Bool) -> Eq (Ty a)
forall a. Eq a => Ty a -> Ty a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ty a -> Ty a -> Bool
$c/= :: forall a. Eq a => Ty a -> Ty a -> Bool
== :: Ty a -> Ty a -> Bool
$c== :: forall a. Eq a => Ty a -> Ty a -> Bool
Eq)

data Rec a m = Rec
  { Rec a m -> Text
recName :: Text
  , Rec a m -> Maybe a
recParam :: Maybe a
  , Rec a m -> [Mem m]
recMems :: [Mem m]
  , Rec a m -> SourceLocation
recLoc :: SourceLocation
  } deriving (Int -> Rec a m -> ShowS
[Rec a m] -> ShowS
Rec a m -> String
(Int -> Rec a m -> ShowS)
-> (Rec a m -> String) -> ([Rec a m] -> ShowS) -> Show (Rec a m)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a m. (Show a, Show m) => Int -> Rec a m -> ShowS
forall a m. (Show a, Show m) => [Rec a m] -> ShowS
forall a m. (Show a, Show m) => Rec a m -> String
showList :: [Rec a m] -> ShowS
$cshowList :: forall a m. (Show a, Show m) => [Rec a m] -> ShowS
show :: Rec a m -> String
$cshow :: forall a m. (Show a, Show m) => Rec a m -> String
showsPrec :: Int -> Rec a m -> ShowS
$cshowsPrec :: forall a m. (Show a, Show m) => Int -> Rec a m -> ShowS
Show, Rec a m -> Rec a m -> Bool
(Rec a m -> Rec a m -> Bool)
-> (Rec a m -> Rec a m -> Bool) -> Eq (Rec a m)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a m. (Eq a, Eq m) => Rec a m -> Rec a m -> Bool
/= :: Rec a m -> Rec a m -> Bool
$c/= :: forall a m. (Eq a, Eq m) => Rec a m -> Rec a m -> Bool
== :: Rec a m -> Rec a m -> Bool
$c== :: forall a m. (Eq a, Eq m) => Rec a m -> Rec a m -> Bool
Eq)

data Mem m = Mem
  { Mem m -> Text
memLabel :: Text
  , Mem m -> Maybe m
memParam :: Maybe m
  , Mem m -> TypeRef
memType :: TypeRef
  , Mem m -> SourceLocation
memLoc :: SourceLocation
  } deriving (Int -> Mem m -> ShowS
[Mem m] -> ShowS
Mem m -> String
(Int -> Mem m -> ShowS)
-> (Mem m -> String) -> ([Mem m] -> ShowS) -> Show (Mem m)
forall m. Show m => Int -> Mem m -> ShowS
forall m. Show m => [Mem m] -> ShowS
forall m. Show m => Mem m -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Mem m] -> ShowS
$cshowList :: forall m. Show m => [Mem m] -> ShowS
show :: Mem m -> String
$cshow :: forall m. Show m => Mem m -> String
showsPrec :: Int -> Mem m -> ShowS
$cshowsPrec :: forall m. Show m => Int -> Mem m -> ShowS
Show, Mem m -> Mem m -> Bool
(Mem m -> Mem m -> Bool) -> (Mem m -> Mem m -> Bool) -> Eq (Mem m)
forall m. Eq m => Mem m -> Mem m -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Mem m -> Mem m -> Bool
$c/= :: forall m. Eq m => Mem m -> Mem m -> Bool
== :: Mem m -> Mem m -> Bool
$c== :: forall m. Eq m => Mem m -> Mem m -> Bool
Eq)

data Adt a m c = Adt
  { Adt a m c -> Text
adtName :: Text
  , Adt a m c -> Maybe a
adtParam :: Maybe a
  , Adt a m c -> [Cons m c]
adtCons :: [Cons m c]
  , Adt a m c -> SourceLocation
adtLoc :: SourceLocation
  } deriving (Int -> Adt a m c -> ShowS
[Adt a m c] -> ShowS
Adt a m c -> String
(Int -> Adt a m c -> ShowS)
-> (Adt a m c -> String)
-> ([Adt a m c] -> ShowS)
-> Show (Adt a m c)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a m c. (Show a, Show c, Show m) => Int -> Adt a m c -> ShowS
forall a m c. (Show a, Show c, Show m) => [Adt a m c] -> ShowS
forall a m c. (Show a, Show c, Show m) => Adt a m c -> String
showList :: [Adt a m c] -> ShowS
$cshowList :: forall a m c. (Show a, Show c, Show m) => [Adt a m c] -> ShowS
show :: Adt a m c -> String
$cshow :: forall a m c. (Show a, Show c, Show m) => Adt a m c -> String
showsPrec :: Int -> Adt a m c -> ShowS
$cshowsPrec :: forall a m c. (Show a, Show c, Show m) => Int -> Adt a m c -> ShowS
Show, Adt a m c -> Adt a m c -> Bool
(Adt a m c -> Adt a m c -> Bool)
-> (Adt a m c -> Adt a m c -> Bool) -> Eq (Adt a m c)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a m c. (Eq a, Eq c, Eq m) => Adt a m c -> Adt a m c -> Bool
/= :: Adt a m c -> Adt a m c -> Bool
$c/= :: forall a m c. (Eq a, Eq c, Eq m) => Adt a m c -> Adt a m c -> Bool
== :: Adt a m c -> Adt a m c -> Bool
$c== :: forall a m c. (Eq a, Eq c, Eq m) => Adt a m c -> Adt a m c -> Bool
Eq)

data Cons m c = Cons
  { Cons m c -> Text
consTag :: Text
  , Cons m c -> Maybe c
consParam :: Maybe c
  , Cons m c -> ConsValue m
consValue :: ConsValue m
  , Cons m c -> SourceLocation
consLoc :: SourceLocation
  } deriving (Int -> Cons m c -> ShowS
[Cons m c] -> ShowS
Cons m c -> String
(Int -> Cons m c -> ShowS)
-> (Cons m c -> String) -> ([Cons m c] -> ShowS) -> Show (Cons m c)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall m c. (Show c, Show m) => Int -> Cons m c -> ShowS
forall m c. (Show c, Show m) => [Cons m c] -> ShowS
forall m c. (Show c, Show m) => Cons m c -> String
showList :: [Cons m c] -> ShowS
$cshowList :: forall m c. (Show c, Show m) => [Cons m c] -> ShowS
show :: Cons m c -> String
$cshow :: forall m c. (Show c, Show m) => Cons m c -> String
showsPrec :: Int -> Cons m c -> ShowS
$cshowsPrec :: forall m c. (Show c, Show m) => Int -> Cons m c -> ShowS
Show, Cons m c -> Cons m c -> Bool
(Cons m c -> Cons m c -> Bool)
-> (Cons m c -> Cons m c -> Bool) -> Eq (Cons m c)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall m c. (Eq c, Eq m) => Cons m c -> Cons m c -> Bool
/= :: Cons m c -> Cons m c -> Bool
$c/= :: forall m c. (Eq c, Eq m) => Cons m c -> Cons m c -> Bool
== :: Cons m c -> Cons m c -> Bool
$c== :: forall m c. (Eq c, Eq m) => Cons m c -> Cons m c -> Bool
Eq)

data ConsValue m
  = ConsValue'None
  | ConsValue'TypeRef [TypeRef]
  | ConsValue'Mems [Mem m]
  deriving (Int -> ConsValue m -> ShowS
[ConsValue m] -> ShowS
ConsValue m -> String
(Int -> ConsValue m -> ShowS)
-> (ConsValue m -> String)
-> ([ConsValue m] -> ShowS)
-> Show (ConsValue m)
forall m. Show m => Int -> ConsValue m -> ShowS
forall m. Show m => [ConsValue m] -> ShowS
forall m. Show m => ConsValue m -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConsValue m] -> ShowS
$cshowList :: forall m. Show m => [ConsValue m] -> ShowS
show :: ConsValue m -> String
$cshow :: forall m. Show m => ConsValue m -> String
showsPrec :: Int -> ConsValue m -> ShowS
$cshowsPrec :: forall m. Show m => Int -> ConsValue m -> ShowS
Show, ConsValue m -> ConsValue m -> Bool
(ConsValue m -> ConsValue m -> Bool)
-> (ConsValue m -> ConsValue m -> Bool) -> Eq (ConsValue m)
forall m. Eq m => ConsValue m -> ConsValue m -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConsValue m -> ConsValue m -> Bool
$c/= :: forall m. Eq m => ConsValue m -> ConsValue m -> Bool
== :: ConsValue m -> ConsValue m -> Bool
$c== :: forall m. Eq m => ConsValue m -> ConsValue m -> Bool
Eq)

--

data Err e
  = Err'Info e
  | Err'NotTopLevelMap
  | Err'TypeMismatch
  | Err'TypeRefMismatch
  | Err'TypeRefParamsMismatch
  | Err'MemMismatch
  | Err'MemsMismatch
  | Err'ConsMismatch
  deriving (Int -> Err e -> ShowS
[Err e] -> ShowS
Err e -> String
(Int -> Err e -> ShowS)
-> (Err e -> String) -> ([Err e] -> ShowS) -> Show (Err e)
forall e. Show e => Int -> Err e -> ShowS
forall e. Show e => [Err e] -> ShowS
forall e. Show e => Err e -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Err e] -> ShowS
$cshowList :: forall e. Show e => [Err e] -> ShowS
show :: Err e -> String
$cshow :: forall e. Show e => Err e -> String
showsPrec :: Int -> Err e -> ShowS
$cshowsPrec :: forall e. Show e => Int -> Err e -> ShowS
Show, Err e -> Err e -> Bool
(Err e -> Err e -> Bool) -> (Err e -> Err e -> Bool) -> Eq (Err e)
forall e. Eq e => Err e -> Err e -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Err e -> Err e -> Bool
$c/= :: forall e. Eq e => Err e -> Err e -> Bool
== :: Err e -> Err e -> Bool
$c== :: forall e. Eq e => Err e -> Err e -> Bool
Eq)

data Error e = Error
  { Error e -> SourceLocation
errorLoc :: SourceLocation
  , Error e -> Err e
errorInfo :: Err e
  } deriving (Int -> Error e -> ShowS
[Error e] -> ShowS
Error e -> String
(Int -> Error e -> ShowS)
-> (Error e -> String) -> ([Error e] -> ShowS) -> Show (Error e)
forall e. Show e => Int -> Error e -> ShowS
forall e. Show e => [Error e] -> ShowS
forall e. Show e => Error e -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Error e] -> ShowS
$cshowList :: forall e. Show e => [Error e] -> ShowS
show :: Error e -> String
$cshow :: forall e. Show e => Error e -> String
showsPrec :: Int -> Error e -> ShowS
$cshowsPrec :: forall e. Show e => Int -> Error e -> ShowS
Show, Error e -> Error e -> Bool
(Error e -> Error e -> Bool)
-> (Error e -> Error e -> Bool) -> Eq (Error e)
forall e. Eq e => Error e -> Error e -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Error e -> Error e -> Bool
$c/= :: forall e. Eq e => Error e -> Error e -> Bool
== :: Error e -> Error e -> Bool
$c== :: forall e. Eq e => Error e -> Error e -> Bool
Eq)

data ParamFns a m c e = ParamFns
  { ParamFns a m c e -> [TokenStep] -> Either [Error e] a
paramFnType :: [TokenStep] -> Either [Error e] a
  , ParamFns a m c e -> [TokenStep] -> Either [Error e] m
paramFnMem :: [TokenStep] -> Either [Error e]  m
  , ParamFns a m c e -> [TokenStep] -> Either [Error e] c
paramFnCons :: [TokenStep] -> Either [Error e]  c
  }

tokenToTypes :: ParamFns a m c e -> TokenStep -> Either [Error e] [Type a m c]
tokenToTypes :: ParamFns a m c e -> TokenStep -> Either [Error e] [Type a m c]
tokenToTypes ParamFns a m c e
fns (SourceLocation
_, Token'Map [(TokenStep, TokenStep)]
ts TokenNote
_) = ((TokenStep, TokenStep) -> Either [Error e] (Type a m c))
-> [(TokenStep, TokenStep)] -> Either [Error e] [Type a m c]
forall a e b.
(a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs ((TokenStep -> TokenStep -> Either [Error e] (Type a m c))
-> (TokenStep, TokenStep) -> Either [Error e] (Type a m c)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((TokenStep -> TokenStep -> Either [Error e] (Type a m c))
 -> (TokenStep, TokenStep) -> Either [Error e] (Type a m c))
-> (TokenStep -> TokenStep -> Either [Error e] (Type a m c))
-> (TokenStep, TokenStep)
-> Either [Error e] (Type a m c)
forall a b. (a -> b) -> a -> b
$ ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Type a m c)
forall a m c e.
ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Type a m c)
tokenToType ParamFns a m c e
fns) [(TokenStep, TokenStep)]
ts
tokenToTypes ParamFns a m c e
_ (SourceLocation
loc, Token
_) = [Error e] -> Either [Error e] [Type a m c]
forall a b. a -> Either a b
Left [SourceLocation -> Err e -> Error e
forall e. SourceLocation -> Err e -> Error e
Error SourceLocation
loc Err e
forall e. Err e
Err'NotTopLevelMap]

tokenToType :: ParamFns a m c e -> TokenStep -> TokenStep -> Either [Error e] (Type a m c)
tokenToType :: ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Type a m c)
tokenToType ParamFns a m c e
fns TokenStep
n TokenStep
v =
  case Ty a -> Type a m c
forall a m c. Ty a -> Type a m c
Type'Ty (Ty a -> Type a m c)
-> Either [Error e] (Ty a) -> Either [Error e] (Type a m c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Ty a)
forall a m c e.
ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Ty a)
tokenToTy ParamFns a m c e
fns TokenStep
n TokenStep
v of
    Right Type a m c
ty -> Type a m c -> Either [Error e] (Type a m c)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type a m c
ty
    Left [Error e]
tyErrs -> case Rec a m -> Type a m c
forall a m c. Rec a m -> Type a m c
Type'Rec (Rec a m -> Type a m c)
-> Either [Error e] (Rec a m) -> Either [Error e] (Type a m c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Rec a m)
forall a m c e.
ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Rec a m)
tokenToRec ParamFns a m c e
fns TokenStep
n TokenStep
v of
      Right Type a m c
rec -> Type a m c -> Either [Error e] (Type a m c)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type a m c
rec
      Left [Error e]
recErrs -> case Adt a m c -> Type a m c
forall a m c. Adt a m c -> Type a m c
Type'Adt (Adt a m c -> Type a m c)
-> Either [Error e] (Adt a m c) -> Either [Error e] (Type a m c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Adt a m c)
forall a m c e.
ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Adt a m c)
tokenToAdt ParamFns a m c e
fns TokenStep
n TokenStep
v of
        Right Type a m c
adt -> Type a m c -> Either [Error e] (Type a m c)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Type a m c
adt
        Left [Error e]
adtErrs -> [Error e] -> Either [Error e] (Type a m c)
forall a b. a -> Either a b
Left ([Error e] -> Either [Error e] (Type a m c))
-> [Error e] -> Either [Error e] (Type a m c)
forall a b. (a -> b) -> a -> b
$ [Error e] -> [Error e] -> [Error e]
forall e. [Error e] -> [Error e] -> [Error e]
betterErrs ([Error e] -> [Error e] -> [Error e]
forall e. [Error e] -> [Error e] -> [Error e]
betterErrs [Error e]
tyErrs [Error e]
recErrs) [Error e]
adtErrs

betterErrs :: [Error e] -> [Error e] -> [Error e]
betterErrs :: [Error e] -> [Error e] -> [Error e]
betterErrs [Error SourceLocation
_ Err e
Err'TypeMismatch] [Error e]
ys = [Error e]
ys
betterErrs [Error e]
xs [Error SourceLocation
_ Err e
Err'TypeMismatch] = [Error e]
xs
betterErrs [Error e]
_ [Error e]
ys = [Error e]
ys -- FIXME: May not be the best fall-through approach

tokenTypeRef :: TokenStep -> Either [Error e] TypeRef
tokenTypeRef :: TokenStep -> Either [Error e] TypeRef
tokenTypeRef (SourceLocation
loc, Token'Text String
name TokenNote
Nothing) = TypeRef -> Either [Error e] TypeRef
forall a b. b -> Either a b
Right (TypeRef -> Either [Error e] TypeRef)
-> TypeRef -> Either [Error e] TypeRef
forall a b. (a -> b) -> a -> b
$ Text -> [TypeRef] -> SourceLocation -> TypeRef
TypeRef (String -> Text
T.pack String
name) [] SourceLocation
loc
tokenTypeRef (SourceLocation
loc, Token'Text String
name (Just [TokenStep]
params)) = Text -> [TypeRef] -> SourceLocation -> TypeRef
TypeRef (String -> Text
T.pack String
name) ([TypeRef] -> SourceLocation -> TypeRef)
-> Either [Error e] [TypeRef]
-> Either [Error e] (SourceLocation -> TypeRef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((TokenStep -> Either [Error e] TypeRef)
-> [TokenStep] -> Either [Error e] [TypeRef]
forall a e b.
(a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs TokenStep -> Either [Error e] TypeRef
forall e. TokenStep -> Either [Error e] TypeRef
tokenTypeRef [TokenStep]
params) Either [Error e] (SourceLocation -> TypeRef)
-> Either [Error e] SourceLocation -> Either [Error e] TypeRef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceLocation -> Either [Error e] SourceLocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceLocation
loc
tokenTypeRef (SourceLocation
loc, Token
_) = [Error e] -> Either [Error e] TypeRef
forall a b. a -> Either a b
Left [SourceLocation -> Err e -> Error e
forall e. SourceLocation -> Err e -> Error e
Error SourceLocation
loc Err e
forall e. Err e
Err'TypeRefMismatch]

tokenToTy :: ParamFns a m c e -> TokenStep -> TokenStep -> Either [Error e] (Ty a)
tokenToTy :: ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Ty a)
tokenToTy ParamFns a m c e
fns (SourceLocation
loc, Token'Text String
t TokenNote
params) TokenStep
v = Text -> Maybe a -> TypeRef -> SourceLocation -> Ty a
forall a. Text -> Maybe a -> TypeRef -> SourceLocation -> Ty a
Ty (String -> Text
T.pack String
t) (Maybe a -> TypeRef -> SourceLocation -> Ty a)
-> Either [Error e] (Maybe a)
-> Either [Error e] (TypeRef -> SourceLocation -> Ty a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
forall e a.
([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams (ParamFns a m c e -> [TokenStep] -> Either [Error e] a
forall a m c e.
ParamFns a m c e -> [TokenStep] -> Either [Error e] a
paramFnType ParamFns a m c e
fns) TokenNote
params Either [Error e] (TypeRef -> SourceLocation -> Ty a)
-> Either [Error e] TypeRef
-> Either [Error e] (SourceLocation -> Ty a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TokenStep -> Either [Error e] TypeRef
forall e. TokenStep -> Either [Error e] TypeRef
tokenTypeRef TokenStep
v Either [Error e] (SourceLocation -> Ty a)
-> Either [Error e] SourceLocation -> Either [Error e] (Ty a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceLocation -> Either [Error e] SourceLocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceLocation
loc
tokenToTy ParamFns a m c e
_ TokenStep
_ (SourceLocation
loc, Token
_) = [Error e] -> Either [Error e] (Ty a)
forall a b. a -> Either a b
Left [SourceLocation -> Err e -> Error e
forall e. SourceLocation -> Err e -> Error e
Error SourceLocation
loc Err e
forall e. Err e
Err'TypeMismatch]

tokenToRec :: ParamFns a m c e -> TokenStep -> TokenStep -> Either [Error e] (Rec a m)
tokenToRec :: ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Rec a m)
tokenToRec ParamFns a m c e
fns (SourceLocation
loc, Token'Text String
name TokenNote
params) TokenStep
v = Text -> Maybe a -> [Mem m] -> SourceLocation -> Rec a m
forall a m. Text -> Maybe a -> [Mem m] -> SourceLocation -> Rec a m
Rec (String -> Text
T.pack String
name) (Maybe a -> [Mem m] -> SourceLocation -> Rec a m)
-> Either [Error e] (Maybe a)
-> Either [Error e] ([Mem m] -> SourceLocation -> Rec a m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
forall e a.
([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams (ParamFns a m c e -> [TokenStep] -> Either [Error e] a
forall a m c e.
ParamFns a m c e -> [TokenStep] -> Either [Error e] a
paramFnType ParamFns a m c e
fns) TokenNote
params Either [Error e] ([Mem m] -> SourceLocation -> Rec a m)
-> Either [Error e] [Mem m]
-> Either [Error e] (SourceLocation -> Rec a m)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParamFns a m c e -> TokenStep -> Either [Error e] [Mem m]
forall a m c e.
ParamFns a m c e -> TokenStep -> Either [Error e] [Mem m]
tokenToMems ParamFns a m c e
fns TokenStep
v Either [Error e] (SourceLocation -> Rec a m)
-> Either [Error e] SourceLocation -> Either [Error e] (Rec a m)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceLocation -> Either [Error e] SourceLocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceLocation
loc
tokenToRec  ParamFns a m c e
_ TokenStep
_ (SourceLocation
loc, Token
_) = [Error e] -> Either [Error e] (Rec a m)
forall a b. a -> Either a b
Left [SourceLocation -> Err e -> Error e
forall e. SourceLocation -> Err e -> Error e
Error SourceLocation
loc Err e
forall e. Err e
Err'TypeMismatch]

tokenToMems :: ParamFns a m c e -> TokenStep -> Either [Error e] [Mem m]
tokenToMems :: ParamFns a m c e -> TokenStep -> Either [Error e] [Mem m]
tokenToMems ParamFns a m c e
fns (SourceLocation
_, Token'Map [(TokenStep, TokenStep)]
mems TokenNote
Nothing) = ParamFns a m c e
-> [(TokenStep, TokenStep)] -> Either [Error e] [Mem m]
forall a m c e.
ParamFns a m c e
-> [(TokenStep, TokenStep)] -> Either [Error e] [Mem m]
tokenToMems' ParamFns a m c e
fns [(TokenStep, TokenStep)]
mems
tokenToMems ParamFns a m c e
_ (SourceLocation
loc, Token
_) = [Error e] -> Either [Error e] [Mem m]
forall a b. a -> Either a b
Left [SourceLocation -> Err e -> Error e
forall e. SourceLocation -> Err e -> Error e
Error SourceLocation
loc Err e
forall e. Err e
Err'MemsMismatch]

tokenToMems' :: ParamFns a m c e -> [(TokenStep,TokenStep)] -> Either [Error e] [Mem m]
tokenToMems' :: ParamFns a m c e
-> [(TokenStep, TokenStep)] -> Either [Error e] [Mem m]
tokenToMems' ParamFns a m c e
fns = ((TokenStep, TokenStep) -> Either [Error e] (Mem m))
-> [(TokenStep, TokenStep)] -> Either [Error e] [Mem m]
forall a e b.
(a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs ((TokenStep -> TokenStep -> Either [Error e] (Mem m))
-> (TokenStep, TokenStep) -> Either [Error e] (Mem m)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((TokenStep -> TokenStep -> Either [Error e] (Mem m))
 -> (TokenStep, TokenStep) -> Either [Error e] (Mem m))
-> (TokenStep -> TokenStep -> Either [Error e] (Mem m))
-> (TokenStep, TokenStep)
-> Either [Error e] (Mem m)
forall a b. (a -> b) -> a -> b
$ ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Mem m)
forall a m c e.
ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Mem m)
tokenToMem ParamFns a m c e
fns)

tokenToMem :: ParamFns a m c e -> TokenStep -> TokenStep -> Either [Error e] (Mem m)
tokenToMem :: ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Mem m)
tokenToMem ParamFns a m c e
fns (SourceLocation
loc, Token'Text String
name TokenNote
params) TokenStep
s = Text -> Maybe m -> TypeRef -> SourceLocation -> Mem m
forall m. Text -> Maybe m -> TypeRef -> SourceLocation -> Mem m
Mem (String -> Text
T.pack String
name) (Maybe m -> TypeRef -> SourceLocation -> Mem m)
-> Either [Error e] (Maybe m)
-> Either [Error e] (TypeRef -> SourceLocation -> Mem m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenStep] -> Either [Error e] m)
-> TokenNote -> Either [Error e] (Maybe m)
forall e a.
([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams (ParamFns a m c e -> [TokenStep] -> Either [Error e] m
forall a m c e.
ParamFns a m c e -> [TokenStep] -> Either [Error e] m
paramFnMem ParamFns a m c e
fns) TokenNote
params Either [Error e] (TypeRef -> SourceLocation -> Mem m)
-> Either [Error e] TypeRef
-> Either [Error e] (SourceLocation -> Mem m)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TokenStep -> Either [Error e] TypeRef
forall e. TokenStep -> Either [Error e] TypeRef
tokenTypeRef TokenStep
s Either [Error e] (SourceLocation -> Mem m)
-> Either [Error e] SourceLocation -> Either [Error e] (Mem m)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceLocation -> Either [Error e] SourceLocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceLocation
loc
tokenToMem ParamFns a m c e
_ TokenStep
_ (SourceLocation
loc, Token
_) = [Error e] -> Either [Error e] (Mem m)
forall a b. a -> Either a b
Left [SourceLocation -> Err e -> Error e
forall e. SourceLocation -> Err e -> Error e
Error SourceLocation
loc Err e
forall e. Err e
Err'MemMismatch]

tokenToAdt :: ParamFns a m c e -> TokenStep -> TokenStep -> Either [Error e] (Adt a m c)
tokenToAdt :: ParamFns a m c e
-> TokenStep -> TokenStep -> Either [Error e] (Adt a m c)
tokenToAdt ParamFns a m c e
fns (SourceLocation
loc, Token'Text String
name TokenNote
params) (SourceLocation
_, Token'List [TokenStep]
conss Wrap
_ TokenNote
Nothing) = Text -> Maybe a -> [Cons m c] -> SourceLocation -> Adt a m c
forall a m c.
Text -> Maybe a -> [Cons m c] -> SourceLocation -> Adt a m c
Adt (String -> Text
T.pack String
name) (Maybe a -> [Cons m c] -> SourceLocation -> Adt a m c)
-> Either [Error e] (Maybe a)
-> Either [Error e] ([Cons m c] -> SourceLocation -> Adt a m c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
forall e a.
([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams (ParamFns a m c e -> [TokenStep] -> Either [Error e] a
forall a m c e.
ParamFns a m c e -> [TokenStep] -> Either [Error e] a
paramFnType ParamFns a m c e
fns) TokenNote
params Either [Error e] ([Cons m c] -> SourceLocation -> Adt a m c)
-> Either [Error e] [Cons m c]
-> Either [Error e] (SourceLocation -> Adt a m c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (TokenStep -> Either [Error e] (Cons m c))
-> [TokenStep] -> Either [Error e] [Cons m c]
forall a e b.
(a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs (ParamFns a m c e -> TokenStep -> Either [Error e] (Cons m c)
forall a m c e.
ParamFns a m c e -> TokenStep -> Either [Error e] (Cons m c)
tokenToCons ParamFns a m c e
fns) [TokenStep]
conss Either [Error e] (SourceLocation -> Adt a m c)
-> Either [Error e] SourceLocation -> Either [Error e] (Adt a m c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceLocation -> Either [Error e] SourceLocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceLocation
loc
tokenToAdt ParamFns a m c e
_ TokenStep
_ (SourceLocation
loc, Token
_) = [Error e] -> Either [Error e] (Adt a m c)
forall a b. a -> Either a b
Left [SourceLocation -> Err e -> Error e
forall e. SourceLocation -> Err e -> Error e
Error SourceLocation
loc Err e
forall e. Err e
Err'TypeMismatch]

tokenToCons :: ParamFns a m c e -> TokenStep -> Either [Error e] (Cons m c)
tokenToCons :: ParamFns a m c e -> TokenStep -> Either [Error e] (Cons m c)
tokenToCons ParamFns a m c e
fns (SourceLocation
loc, Token'Text String
name TokenNote
params) =  Text -> Maybe c -> ConsValue m -> SourceLocation -> Cons m c
forall m c.
Text -> Maybe c -> ConsValue m -> SourceLocation -> Cons m c
Cons (String -> Text
T.pack String
name) (Maybe c -> ConsValue m -> SourceLocation -> Cons m c)
-> Either [Error e] (Maybe c)
-> Either [Error e] (ConsValue m -> SourceLocation -> Cons m c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenStep] -> Either [Error e] c)
-> TokenNote -> Either [Error e] (Maybe c)
forall e a.
([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams (ParamFns a m c e -> [TokenStep] -> Either [Error e] c
forall a m c e.
ParamFns a m c e -> [TokenStep] -> Either [Error e] c
paramFnCons ParamFns a m c e
fns) TokenNote
params Either [Error e] (ConsValue m -> SourceLocation -> Cons m c)
-> Either [Error e] (ConsValue m)
-> Either [Error e] (SourceLocation -> Cons m c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ConsValue m -> Either [Error e] (ConsValue m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConsValue m
forall m. ConsValue m
ConsValue'None Either [Error e] (SourceLocation -> Cons m c)
-> Either [Error e] SourceLocation -> Either [Error e] (Cons m c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceLocation -> Either [Error e] SourceLocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceLocation
loc
tokenToCons ParamFns a m c e
fns (SourceLocation
loc, Token'List [(SourceLocation
_, Token'Text String
name TokenNote
Nothing)] Wrap
_ TokenNote
params) = Text -> Maybe c -> ConsValue m -> SourceLocation -> Cons m c
forall m c.
Text -> Maybe c -> ConsValue m -> SourceLocation -> Cons m c
Cons (String -> Text
T.pack String
name) (Maybe c -> ConsValue m -> SourceLocation -> Cons m c)
-> Either [Error e] (Maybe c)
-> Either [Error e] (ConsValue m -> SourceLocation -> Cons m c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenStep] -> Either [Error e] c)
-> TokenNote -> Either [Error e] (Maybe c)
forall e a.
([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams (ParamFns a m c e -> [TokenStep] -> Either [Error e] c
forall a m c e.
ParamFns a m c e -> [TokenStep] -> Either [Error e] c
paramFnCons ParamFns a m c e
fns) TokenNote
params Either [Error e] (ConsValue m -> SourceLocation -> Cons m c)
-> Either [Error e] (ConsValue m)
-> Either [Error e] (SourceLocation -> Cons m c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ConsValue m -> Either [Error e] (ConsValue m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConsValue m
forall m. ConsValue m
ConsValue'None Either [Error e] (SourceLocation -> Cons m c)
-> Either [Error e] SourceLocation -> Either [Error e] (Cons m c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceLocation -> Either [Error e] SourceLocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceLocation
loc
tokenToCons ParamFns a m c e
fns (SourceLocation
loc, Token'List [(SourceLocation
_, Token'Text String
name TokenNote
Nothing), (SourceLocation
_, Token'Map [(TokenStep, TokenStep)]
mems TokenNote
Nothing)] Wrap
_ TokenNote
params) = do
  [Mem m]
ms <- ParamFns a m c e
-> [(TokenStep, TokenStep)] -> Either [Error e] [Mem m]
forall a m c e.
ParamFns a m c e
-> [(TokenStep, TokenStep)] -> Either [Error e] [Mem m]
tokenToMems' ParamFns a m c e
fns [(TokenStep, TokenStep)]
mems
  Maybe c
param <- ([TokenStep] -> Either [Error e] c)
-> TokenNote -> Either [Error e] (Maybe c)
forall e a.
([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams (ParamFns a m c e -> [TokenStep] -> Either [Error e] c
forall a m c e.
ParamFns a m c e -> [TokenStep] -> Either [Error e] c
paramFnCons ParamFns a m c e
fns) TokenNote
params
  Cons m c -> Either [Error e] (Cons m c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Cons m c -> Either [Error e] (Cons m c))
-> Cons m c -> Either [Error e] (Cons m c)
forall a b. (a -> b) -> a -> b
$ Text -> Maybe c -> ConsValue m -> SourceLocation -> Cons m c
forall m c.
Text -> Maybe c -> ConsValue m -> SourceLocation -> Cons m c
Cons
    (String -> Text
T.pack String
name)
    Maybe c
param
    (if [Mem m] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Mem m]
ms
      then ConsValue m
forall m. ConsValue m
ConsValue'None
      else [Mem m] -> ConsValue m
forall m. [Mem m] -> ConsValue m
ConsValue'Mems [Mem m]
ms)
    SourceLocation
loc
tokenToCons ParamFns a m c e
fns (SourceLocation
loc, (Token'List ((SourceLocation
_, Token'Text String
name TokenNote
Nothing):[TokenStep]
xs) Wrap
_ TokenNote
params)) = Text -> Maybe c -> ConsValue m -> SourceLocation -> Cons m c
forall m c.
Text -> Maybe c -> ConsValue m -> SourceLocation -> Cons m c
Cons (String -> Text
T.pack String
name) (Maybe c -> ConsValue m -> SourceLocation -> Cons m c)
-> Either [Error e] (Maybe c)
-> Either [Error e] (ConsValue m -> SourceLocation -> Cons m c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenStep] -> Either [Error e] c)
-> TokenNote -> Either [Error e] (Maybe c)
forall e a.
([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams (ParamFns a m c e -> [TokenStep] -> Either [Error e] c
forall a m c e.
ParamFns a m c e -> [TokenStep] -> Either [Error e] c
paramFnCons ParamFns a m c e
fns) TokenNote
params Either [Error e] (ConsValue m -> SourceLocation -> Cons m c)
-> Either [Error e] (ConsValue m)
-> Either [Error e] (SourceLocation -> Cons m c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([TypeRef] -> ConsValue m
forall m. [TypeRef] -> ConsValue m
ConsValue'TypeRef ([TypeRef] -> ConsValue m)
-> Either [Error e] [TypeRef] -> Either [Error e] (ConsValue m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TokenStep -> Either [Error e] TypeRef)
-> [TokenStep] -> Either [Error e] [TypeRef]
forall a e b.
(a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs TokenStep -> Either [Error e] TypeRef
forall e. TokenStep -> Either [Error e] TypeRef
tokenTypeRef [TokenStep]
xs) Either [Error e] (SourceLocation -> Cons m c)
-> Either [Error e] SourceLocation -> Either [Error e] (Cons m c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SourceLocation -> Either [Error e] SourceLocation
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceLocation
loc
tokenToCons ParamFns a m c e
_ (SourceLocation
loc,Token
_) = [Error e] -> Either [Error e] (Cons m c)
forall a b. a -> Either a b
Left [SourceLocation -> Err e -> Error e
forall e. SourceLocation -> Err e -> Error e
Error SourceLocation
loc Err e
forall e. Err e
Err'ConsMismatch]

mapWithErrs :: (a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs :: (a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs a -> Either [Error e] b
_ [] = [b] -> Either [Error e] [b]
forall a b. b -> Either a b
Right []
mapWithErrs a -> Either [Error e] b
f (a
x:[a]
xs) = case a -> Either [Error e] b
f a
x of
  Left [Error e]
es -> case (a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
forall a e b.
(a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs a -> Either [Error e] b
f [a]
xs of
    Left [Error e]
es' -> [Error e] -> Either [Error e] [b]
forall a b. a -> Either a b
Left ([Error e] -> Either [Error e] [b])
-> [Error e] -> Either [Error e] [b]
forall a b. (a -> b) -> a -> b
$ [Error e]
es [Error e] -> [Error e] -> [Error e]
forall a. [a] -> [a] -> [a]
++ [Error e]
es'
    Right [b]
_ -> [Error e] -> Either [Error e] [b]
forall a b. a -> Either a b
Left [Error e]
es
  Right b
y -> case (a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
forall a e b.
(a -> Either [Error e] b) -> [a] -> Either [Error e] [b]
mapWithErrs a -> Either [Error e] b
f [a]
xs of
    Left [Error e]
es -> [Error e] -> Either [Error e] [b]
forall a b. a -> Either a b
Left [Error e]
es
    Right [b]
ys -> [b] -> Either [Error e] [b]
forall a b. b -> Either a b
Right ([b] -> Either [Error e] [b]) -> [b] -> Either [Error e] [b]
forall a b. (a -> b) -> a -> b
$ b
y b -> [b] -> [b]
forall a. a -> [a] -> [a]
: [b]
ys

tokenParams :: ([TokenStep] -> Either [Error e] a) -> Maybe [TokenStep] -> Either [Error e] (Maybe a)
tokenParams :: ([TokenStep] -> Either [Error e] a)
-> TokenNote -> Either [Error e] (Maybe a)
tokenParams [TokenStep] -> Either [Error e] a
f TokenNote
params = case TokenNote
params of
  TokenNote
Nothing -> Maybe a -> Either [Error e] (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
  Just [TokenStep]
ps -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> Either [Error e] a -> Either [Error e] (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TokenStep] -> Either [Error e] a
f [TokenStep]
ps