rc #13
@@ -1,5 +1,6 @@
|
|||||||
-- Show Y
|
-- Show Y
|
||||||
{-# LANGUAGE UndecidableInstances #-}
|
{-# LANGUAGE UndecidableInstances #-}
|
||||||
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
module Rlp.ParseDecls
|
module Rlp.ParseDecls
|
||||||
(
|
(
|
||||||
@@ -17,6 +18,7 @@ import Data.List (foldl1')
|
|||||||
import Data.Void
|
import Data.Void
|
||||||
import Data.Char
|
import Data.Char
|
||||||
import Data.Functor
|
import Data.Functor
|
||||||
|
import Data.Functor.Foldable
|
||||||
import Data.HashMap.Strict qualified as H
|
import Data.HashMap.Strict qualified as H
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
@@ -83,7 +85,7 @@ partialExpr = choice
|
|||||||
|
|
||||||
partialExpr1 :: Parser PartialExpr'
|
partialExpr1 :: Parser PartialExpr'
|
||||||
partialExpr1 = choice
|
partialExpr1 = choice
|
||||||
[ try $ char '(' *> partialExpr <* char ')'
|
[ try $ char '(' *> (hoistY P <$> partialExpr) <* char ')'
|
||||||
, fmap Y $ varid'
|
, fmap Y $ varid'
|
||||||
, fmap Y $ lit'
|
, fmap Y $ lit'
|
||||||
]
|
]
|
||||||
@@ -144,19 +146,21 @@ newtype Y f = Y (f (Y f))
|
|||||||
unY :: Y f -> f (Y f)
|
unY :: Y f -> f (Y f)
|
||||||
unY (Y f) = f
|
unY (Y f) = f
|
||||||
|
|
||||||
ymap :: (Functor f) => (forall a. f a -> g a) -> Y f -> Y g
|
hoistY :: (Functor f) => (forall a. f a -> g a) -> Y f -> Y g
|
||||||
ymap m (Y f) = Y $ m (ymap m <$> f)
|
hoistY m (Y f) = Y $ m (hoistY m <$> f)
|
||||||
|
|
||||||
instance (Show (f (Y f))) => Show (Y f) where
|
instance (Show (f (Y f))) => Show (Y f) where
|
||||||
showsPrec p (Y f) = showsPrec p f
|
showsPrec p (Y f) = showsPrec p f
|
||||||
|
|
||||||
data Partial a = E (RlpExprF Name a)
|
data Partial a = E (RlpExprF Name a)
|
||||||
| U (Partial a) Name (Partial a)
|
| U (Partial a) Name (Partial a)
|
||||||
deriving Show
|
| P (Partial a)
|
||||||
|
deriving (Show, Functor)
|
||||||
|
|
||||||
type PartialExpr' = Y Partial
|
type PartialExpr' = Y Partial
|
||||||
|
|
||||||
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
mkOp :: RlpExpr b -> RlpExpr b -> RlpExpr b -> RlpExpr b
|
||||||
|
mkOp f a b = (f `AppE` a) `AppE` b
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
module Rlp.Syntax
|
module Rlp.Syntax
|
||||||
( RlpExpr(..)
|
( RlpExpr(..)
|
||||||
|
, RlpExpr'
|
||||||
, RlpExprF(..)
|
, RlpExprF(..)
|
||||||
, RlpExprF'
|
, RlpExprF'
|
||||||
, Decl(..)
|
, Decl(..)
|
||||||
@@ -61,6 +62,8 @@ data RlpExpr b = LetE [Bind b] (RlpExpr b)
|
|||||||
| LitE (Lit b)
|
| LitE (Lit b)
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
|
type RlpExpr' = RlpExpr Name
|
||||||
|
|
||||||
-- do we want guards?
|
-- do we want guards?
|
||||||
data Alt b = AltA (Pat b) (RlpExpr b)
|
data Alt b = AltA (Pat b) (RlpExpr b)
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|||||||
Reference in New Issue
Block a user