mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 16:51:42 +03:00
Generate FromNoun code for record types.
This commit is contained in:
parent
f680e44ad5
commit
4a666d1aa6
@ -91,8 +91,7 @@ deriveFromNoun tyName = do
|
|||||||
enumFromAtom :: [Name] -> Exp
|
enumFromAtom :: [Name] -> Exp
|
||||||
enumFromAtom nms = LamE [VarP n] body
|
enumFromAtom nms = LamE [VarP n] body
|
||||||
where
|
where
|
||||||
n = mkName "n"
|
(n, c) = (mkName "n", mkName "c")
|
||||||
c = mkName "c"
|
|
||||||
getCord = BindS (VarP c) $ AppE (VarE 'parseNoun) (VarE n)
|
getCord = BindS (VarP c) $ AppE (VarE 'parseNoun) (VarE n)
|
||||||
examine = NoBindS $ CaseE (VarE c) (matches ++ [fallback])
|
examine = NoBindS $ CaseE (VarE c) (matches ++ [fallback])
|
||||||
matches = mkMatch <$> nms
|
matches = mkMatch <$> nms
|
||||||
@ -104,8 +103,18 @@ enumFromAtom nms = LamE [VarP n] body
|
|||||||
(NormalB $ AppE (VarE 'pure) (ConE n))
|
(NormalB $ AppE (VarE 'pure) (ConE n))
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
applyE :: Exp -> [Exp] -> Exp
|
||||||
|
applyE e [] = e
|
||||||
|
applyE e (a:as) = applyE (AppE e a) as
|
||||||
|
|
||||||
tupFromNoun :: ConInfo -> Exp
|
tupFromNoun :: ConInfo -> Exp
|
||||||
tupFromNoun _ = VarE 'undefined
|
tupFromNoun (n, tys) = LamE [VarP x] body
|
||||||
|
where
|
||||||
|
x = mkName "x"
|
||||||
|
vars = mkName . singleton . fst <$> zip ['a'..] tys
|
||||||
|
body = DoE [getTup, convert]
|
||||||
|
convert = NoBindS $ AppE (VarE 'pure) $ applyE (ConE n) (VarE <$> vars)
|
||||||
|
getTup = BindS (TupP $ VarP <$> vars) $ AppE (VarE 'parseNoun) (VarE x)
|
||||||
|
|
||||||
sumFromNoun :: [ConInfo] -> Exp
|
sumFromNoun :: [ConInfo] -> Exp
|
||||||
sumFromNoun _ = VarE 'undefined
|
sumFromNoun _ = VarE 'undefined
|
||||||
|
@ -34,22 +34,15 @@ data EffBs
|
|||||||
| EBLolr Word Word
|
| EBLolr Word Word
|
||||||
|
|
||||||
data RecEx = RE Word Word
|
data RecEx = RE Word Word
|
||||||
|
deriving (Eq, Ord, Show)
|
||||||
|
|
||||||
data NewtEx = NE Word
|
data NewtEx = NE Word
|
||||||
|
deriving (Eq, Ord, Show)
|
||||||
|
|
||||||
deriveNoun ''EffBs
|
deriveNoun ''EffBs
|
||||||
deriveNoun ''RecEx
|
deriveNoun ''RecEx
|
||||||
deriveNoun ''NewtEx
|
deriveNoun ''NewtEx
|
||||||
|
|
||||||
{-
|
|
||||||
instance FromNoun PutDel where
|
|
||||||
parseNoun n = do
|
|
||||||
parseNoun n >>= \case
|
|
||||||
Cord "put" -> pure Put
|
|
||||||
Cord "del" -> pure Del
|
|
||||||
Cord cord -> fail ("Invalid turf operation: " <> show cord)
|
|
||||||
-}
|
|
||||||
|
|
||||||
data Eff
|
data Eff
|
||||||
= HttpServer Server.Eff
|
= HttpServer Server.Eff
|
||||||
| HttpClient Client.Eff
|
| HttpClient Client.Eff
|
||||||
|
Loading…
Reference in New Issue
Block a user