diff --git a/lib/src/Okapi/NewDSL.hs b/lib/src/Okapi/NewDSL.hs index 0e69a3d..423fe22 100644 --- a/lib/src/Okapi/NewDSL.hs +++ b/lib/src/Okapi/NewDSL.hs @@ -12,15 +12,16 @@ import Data.Kind (Type) -- type Interpreter (expr :: * -> *) state error a = state -> expr a -> (Either error a, state) -class Evalable (expr :: * -> *) state error where - eval :: state -> expr a -> (Either error a, state) +class Context (expr :: * -> *) state error where + eval :: state -> expr a -> (Either error a, state) data DSL (expr :: * -> *) state error a where FMap :: (a -> a') -> DSL expr state error a -> DSL expr state error a' Pure :: a -> DSL expr state error a Apply :: DSL expr state error (a -> b) -> DSL expr state error a -> DSL expr state error b -- Eval :: Interpreter expr state error a -> expr a -> DSL expr state error a - Eval :: Evalable expr state error => expr a -> DSL expr state error a + Expr :: Context expr state error => expr a -> DSL expr state error a -- Call Quote? + -- Add constructor for Combinator?? instance Functor (DSL expr state error) where fmap = FMap @@ -29,7 +30,7 @@ instance Applicative (DSL expr state error) where pure = Pure (<*>) = Apply -exec :: Evalable expr state error => state -> DSL expr state error a -> (Either error a, state) +exec :: Context expr state error => state -> DSL expr state error a -> (Either error a, state) exec state (FMap f expr) = case exec state expr of (Left e, state') -> (Left e, state') (Right o, state') -> (Right $ f o, state') @@ -39,4 +40,7 @@ exec state (Apply progF progX) = case exec state progF of (Right x, state'') -> (Right $ f x, state'') (Left e, state'') -> (Left e, state'') (Left e, state') -> (Left e, state') -exec state (Eval expr) = eval state expr +exec state (Expr expr) = eval state expr + +-- expr :: Context expr state error => expr a -> DSL expr state error a +-- expr = Expr diff --git a/lib/src/Okapi/Parser/Path.hs b/lib/src/Okapi/Parser/Path.hs index fc5639c..cece54b 100644 --- a/lib/src/Okapi/Parser/Path.hs +++ b/lib/src/Okapi/Parser/Path.hs @@ -15,6 +15,8 @@ import qualified Web.HttpApiData as Web data Expr a where Static :: Web.ToHttpApiData a => a -> Expr () Param :: Web.FromHttpApiData a => Expr a +-- Optional :: Expr a -> Expr (Maybe a) + Macro :: Context expr state error => DSL expr state error a -> Expr a End :: Expr () type State = [Text] @@ -22,23 +24,28 @@ type State = [Text] data Error where Error :: Text -> Error -instance Evalable Expr State Error where +instance Context Expr State Error where eval state expr = case expr of Static @t x -> undefined Param @t -> undefined + -- Optional expr' -> undefined + Macro dsl -> undefined End -> undefined -- embed :: Expr a -> DSL Expr State Error a -- embed = Eval interpreter static :: Web.ToHttpApiData a => a -> DSL Expr State Error () -static = Eval . Static +static = Expr . Static param :: Web.FromHttpApiData a => DSL Expr State Error a -param = Eval Param +param = Expr Param + +-- optional :: Expr a -> DSL Expr State Error (Maybe a) +-- optional = Expr . Optional end :: Web.FromHttpApiData a => DSL Expr State Error () -end = Eval End +end = Expr End -- instance DSL Expr [Text] Error where -- eval :: Expr -> [Text] -> (Either Error Result, [Text])