, Type_Root_Lift Type_Bool (Type_Root_of_Expr root)
, Error_Type_Lift (Error_Type_Fun AST)
(Error_of_Type AST (Type_Root_of_Expr root))
- , Error_Expr_Lift (Error_Expr_Lambda (Error_of_Type AST (Type_Root_of_Expr root))
- ( Type_Root_of_Expr root)
- AST)
+ , Error_Expr_Lift (Error_Expr (Error_of_Type AST (Type_Root_of_Expr root))
+ ( Type_Root_of_Expr root)
+ AST)
(Error_of_Expr AST root)
- , Error_Expr_Lift (Error_Expr AST) (Error_of_Expr AST root)
, Type_Unlift Type_Bool (Type_of_Expr root)
case asts of
[AST ast_bool []] ->
case read_safe ast_bool of
- Left err -> Left $ error_expr_lift $ Error_Expr_Read err ast
+ Left err -> Left $ error_expr $ Error_Expr_Read err ast
Right (i::Bool) ->
k type_bool $ Forall_Repr_with_Context $
const $ bool i
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 3 ast
AST "not" asts -> unary_from asts not
AST "and" asts -> binary_from asts and
AST "or" asts -> binary_from asts or
AST "xor" asts -> binary_from asts xor
- -- _ -> Left $ error_expr_lift $ Error_Expr_Unsupported_here ast
_ -> Left $
case hbool :: HBool (Is_Last_Expr (Expr_Bool root) root) of
- HTrue -> error_expr_lift $ Error_Expr_Unsupported ast
- HFalse -> error_expr_lift $ Error_Expr_Unsupported_here ast
+ HTrue -> error_expr $ Error_Expr_Unsupported ast
+ HFalse -> error_expr $ Error_Expr_Unsupported_here ast
where
unary_from asts
(op::forall repr. Sym_Bool repr
case type_unlift $ unType_Root ty_x of
Just (Type_Bool::Type_Bool (Type_Root_of_Expr root) h_x) ->
k ty_x $ Forall_Repr_with_Context (op . x)
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Argument_mismatch
(Exists_Type type_bool)
(Exists_Type ty_x) ast
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 1 ast
binary_from asts
(op::forall repr. Sym_Bool repr
Just (Type_Bool::Type_Bool (Type_Root_of_Expr root) h_y) ->
k ty_x $ Forall_Repr_with_Context $
\c -> x c `op` y c
- Nothing -> Left $ error_lambda_lift $
+ Nothing -> Left $ error_expr $
Error_Expr_Fun_Argument_mismatch
(Exists_Type type_bool)
(Exists_Type ty_y) ast
- Nothing -> Left $ error_lambda_lift $
+ Nothing -> Left $ error_expr $
Error_Expr_Fun_Argument_mismatch
(Exists_Type type_bool)
(Exists_Type ty_x) ast
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 2 ast
- error_lambda_lift
- :: Error_Expr_Lambda (Error_of_Type AST (Type_Root_of_Expr root)) (Type_Root_of_Expr root) AST
+ error_expr
+ :: Error_Expr (Error_of_Type AST (Type_Root_of_Expr root)) (Type_Root_of_Expr root) AST
-> Error_of_Expr AST root
- error_lambda_lift = error_expr_lift
+ error_expr = error_expr_lift
-- ** Type 'Expr_Lambda_Bool'
-- | Convenient alias.
Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
case ty `type_eq` ty_expected of
Nothing -> return $ Left $
- error_lambda_lift $ Error_Expr_Type
+ error_expr $ Error_Expr_Type
(error_type_lift $ Error_Type_Unsupported_here raw) raw
Just Refl -> do
h <- host_from_expr r
-- , (string_from_expr :: Repr_String IO h -> String) r
)
where
- error_lambda_lift
+ error_expr
:: (root ~ Expr_Lambda_Bool IO)
- => Error_Expr_Lambda (Error_of_Type raw (Type_Root_of_Expr root))
- (Type_Root_of_Expr root)
- raw
+ => Error_Expr (Error_of_Type raw (Type_Root_of_Expr root))
+ (Type_Root_of_Expr root)
+ raw
-> Error_of_Expr raw root
- error_lambda_lift = error_expr_lift
+ error_expr = error_expr_lift
tests :: TestTree
tests = testGroup "Bool" $
= Type_of_Expr (ex (Expr_Root ex))
-- NOTE: require UndecidableInstances.
type instance Error_of_Expr ast (Expr_Root ex)
- = Error_Expr_Alt (Error_Expr ast)
- (Error_of_Expr ast (ex (Expr_Root ex)))
+ = Error_Expr_Alt (Error_Expr (Error_of_Type ast (Type_Root_of_Expr (ex (Expr_Root ex))))
+ (Type_Root_of_Expr (ex (Expr_Root ex)))
+ ast)
+ (Error_of_Expr ast (ex (Expr_Root ex)))
-- NOTE: require UndecidableInstances.
type instance Sym_of_Expr (Expr_Root ex) repr
= Sym_of_Expr (ex (Expr_Root ex)) repr
-}
-- * Type 'Expr_Alt'
--- | Combine two expressions into one.
+-- | Expression making an alternative between two expressions.
data Expr_Alt curr next (root:: *)
= Expr_Alt_Curr (curr root)
| Expr_Alt_Next (next root)
, Expr_from ast (next root)
, Root_of_Expr (curr root) ~ root
, Root_of_Expr (next root) ~ root
- , Error_Expr_Unlift (Error_Expr ast) (Error_of_Expr ast root)
+ , Error_Expr_Unlift (Error_Expr (Error_of_Type ast (Type_Root_of_Expr root))
+ (Type_Root_of_Expr root) ast)
+ (Error_of_Expr ast root)
) => Expr_from ast (Expr_Alt curr next root) where
expr_from _px_ex ctx ast k =
case expr_from (Proxy::Proxy (curr root)) ctx ast $
Right ret -> ret
Left err ->
case error_expr_unlift err of
- Just (Error_Expr_Unsupported_here (_::ast)) ->
+ Just (Error_Expr_Unsupported_here _
+ :: Error_Expr (Error_of_Type ast (Type_Root_of_Expr root))
+ (Type_Root_of_Expr root) ast) ->
expr_from (Proxy::Proxy (next root)) ctx ast $
\ty (Forall_Repr_with_Context repr) ->
k ty (Forall_Repr_with_Context repr)
expr_unliftN _ (Expr_Alt_Curr _) = Nothing
-}
+-- * Type family 'Is_Last_Expr'
+-- | Return whether a given expression is the last one in a given expression stack.
+--
+-- NOTE: each expression parser uses this type family
+-- when it encounters unsupported syntax:
+-- to know if it is the last expression parser component that will be tried
+-- (and thus return 'Error_Expr_Unsupported')
+-- or if some other expression parser component shall be tried
+-- (and thus return 'Error_Expr_Unsupported_here',
+-- which is then handled accordingly by the 'Expr_from' instance of 'Expr_Alt').
+type family Is_Last_Expr (ex:: *) (exs:: *) :: Bool where
+ Is_Last_Expr ex ex = 'True
+ Is_Last_Expr ex (Expr_Root exs) = Is_Last_Expr ex (exs (Expr_Root exs))
+ Is_Last_Expr (ex root) (Expr_Alt ex next root) = 'False
+ Is_Last_Expr other (Expr_Alt curr next root) = Is_Last_Expr other (next root)
+
-- * Type 'Error_Expr_Alt'
--- | Combine two expression errors into one.
+-- | Error expression making an alternative between two error expressions.
data Error_Expr_Alt curr next
= Error_Expr_Alt_Curr curr
| Error_Expr_Alt_Next next
err -> errs
error_expr_lift = error_expr_liftN (Proxy::Proxy (Peano_of_Error_Expr err errs))
--- * Type family 'Is_Last_Expr'
-type family Is_Last_Expr (ex:: *) (exs:: *) :: Bool where
- Is_Last_Expr ex ex = 'True
- Is_Last_Expr ex (Expr_Root exs) = Is_Last_Expr ex (exs (Expr_Root exs))
- Is_Last_Expr (ex root) (Expr_Alt ex next root) = 'False
- Is_Last_Expr other (Expr_Alt curr next root) = Is_Last_Expr other (next root)
-
-- *** Type family 'Peano_of_Error_Expr'
-- | Return a 'Peano' number derived from the location
-- of a given error expression within a given error expression stack,
-- ** Type 'Error_Expr_Read'
-- | Common expression errors.
-data Error_Expr ast
- = Error_Expr_Read Error_Read ast
+data Error_Expr err_ty ty ast
+ = Error_Expr_Fun_Wrong_number_of_arguments Int ast
+ | Error_Expr_Fun_Argument_mismatch (Exists_Type ty) (Exists_Type ty) ast
+ | Error_Expr_Read Error_Read ast
+ | Error_Expr_Type err_ty ast
| Error_Expr_Unsupported ast
-- ^ Given syntax is supported by none
-- of the expression parser components
, Type_Root_Lift Type_Int (Type_Root_of_Expr root)
, Error_Type_Lift (Error_Type_Fun AST)
(Error_of_Type AST (Type_Root_of_Expr root))
- , Error_Expr_Lift (Error_Expr_Lambda (Error_of_Type AST (Type_Root_of_Expr root))
- ( Type_Root_of_Expr root)
- AST)
+ , Error_Expr_Lift (Error_Expr (Error_of_Type AST (Type_Root_of_Expr root))
+ ( Type_Root_of_Expr root)
+ AST)
(Error_of_Expr AST root)
- , Error_Expr_Lift (Error_Expr AST) (Error_of_Expr AST root)
, Type_Unlift Type_Int (Type_of_Expr root)
case asts of
[AST ast_int []] ->
case read_safe ast_int of
- Left err -> Left $ error_expr_lift $ Error_Expr_Read err ast
+ Left err -> Left $ error_expr $ Error_Expr_Read err ast
Right (i::Int) ->
k type_int $ Forall_Repr_with_Context $
const $ int i
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 3 ast
AST "neg" asts -> unary_from asts neg
AST "add" asts -> binary_from asts add
- -- _ -> Left $ error_expr_lift $ Error_Expr_Unsupported_here ast
_ -> Left $
case hbool :: HBool (Is_Last_Expr (Expr_Int root) root) of
- HTrue -> error_expr_lift $ Error_Expr_Unsupported ast
- HFalse -> error_expr_lift $ Error_Expr_Unsupported_here ast
+ HTrue -> error_expr $ Error_Expr_Unsupported ast
+ HFalse -> error_expr $ Error_Expr_Unsupported_here ast
where
unary_from asts
(op::forall repr. Sym_Int repr
case type_unlift $ unType_Root ty_x of
Just (Type_Int::Type_Int (Type_Root_of_Expr root) h_x) ->
k ty_x $ Forall_Repr_with_Context (op . x)
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Argument_mismatch
(Exists_Type type_int)
(Exists_Type ty_x) ast
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 1 ast
binary_from asts
(op::forall repr. Sym_Int repr
Just (Type_Int::Type_Int (Type_Root_of_Expr root) h_y) ->
k ty_x $ Forall_Repr_with_Context $
\c -> x c `op` y c
- Nothing -> Left $ error_lambda_lift $
+ Nothing -> Left $ error_expr $
Error_Expr_Fun_Argument_mismatch
(Exists_Type type_int)
(Exists_Type ty_y) ast
- Nothing -> Left $ error_lambda_lift $
+ Nothing -> Left $ error_expr $
Error_Expr_Fun_Argument_mismatch
(Exists_Type type_int)
(Exists_Type ty_x) ast
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 2 ast
- error_lambda_lift
- :: Error_Expr_Lambda (Error_of_Type AST (Type_Root_of_Expr root)) (Type_Root_of_Expr root) AST
+ error_expr
+ :: Error_Expr (Error_of_Type AST (Type_Root_of_Expr root)) (Type_Root_of_Expr root) AST
-> Error_of_Expr AST root
- error_lambda_lift = error_expr_lift
+ error_expr = error_expr_lift
-- ** Type 'Expr_Lambda_Int'
-- | Convenient alias.
Right (Exists_Type_and_Repr ty (Forall_Repr r)) ->
case ty `type_eq` ty_expected of
Nothing -> return $ Left $
- error_lambda_lift $ Error_Expr_Type
+ error_expr $ Error_Expr_Type
(error_type_lift $ Error_Type_Unsupported raw) raw
Just Refl -> do
h <- host_from_expr r
-- , (string_from_expr :: Repr_String IO h -> String) r
)
where
- error_lambda_lift
+ error_expr
:: (root ~ Expr_Lambda_Int IO)
- => Error_Expr_Lambda (Error_of_Type raw (Type_Root_of_Expr root))
- (Type_Root_of_Expr root)
- raw
+ => Error_Expr (Error_of_Type raw (Type_Root_of_Expr root))
+ (Type_Root_of_Expr root)
+ raw
-> Error_of_Expr raw root
- error_lambda_lift = error_expr_lift
+ error_expr = error_expr_lift
tests :: TestTree
tests = testGroup "Int" $
type instance Type_of_Expr (Expr_Lambda lam root) = Type_Fun lam
type instance Sym_of_Expr (Expr_Lambda lam root) repr = Sym_Lambda lam repr
type instance Error_of_Expr ast (Expr_Lambda lam root)
- = Error_Expr_Lambda (Error_of_Type ast (Type_Root_of_Expr root))
- (Type_Root_of_Expr root)
- ast
+ = Error_Expr_Lambda ast
-- NOTE: require UndecidableInstances.
instance -- Expr_from AST Expr_Lambda
, Error_Type_Lift (Error_Type_Fun AST)
(Error_of_Type AST (Type_Root_of_Expr root))
-- NOTE: require UndecidableInstances.
- , Error_Expr_Lift (Error_Expr_Lambda (Error_of_Type AST (Type_Root_of_Expr root))
- ( Type_Root_of_Expr root)
- AST)
+ , Error_Expr_Lift (Error_Expr_Lambda AST)
(Error_of_Expr AST root)
-- NOTE: require UndecidableInstances.
- , Error_Expr_Lift (Error_Expr AST) (Error_of_Expr AST root)
+ , Error_Expr_Lift (Error_Expr (Error_of_Type AST (Type_Root_of_Expr root))
+ ( Type_Root_of_Expr root)
+ AST)
+ (Error_of_Expr AST root)
-- NOTE: require UndecidableInstances.
- , Error_Expr_Unlift (Error_Expr AST) (Error_of_Expr AST root)
+ , Error_Expr_Unlift (Error_Expr (Error_of_Type AST (Type_Root_of_Expr root))
+ ( Type_Root_of_Expr root)
+ AST)
+ (Error_of_Expr AST root)
-- NOTE: require UndecidableInstances.
, Type_Unlift (Type_Fun lam) (Type_of_Expr root)
-> Either (Error_of_Expr AST root) ret
go c k' =
case c of
- Context_Empty -> Left $ error_lambda_lift $
+ Context_Empty -> Left $ error_expr_lift $
Error_Expr_Lambda_Var_unbound name ast
Var n ty `Context_Alt_Next` _ | n == name ->
k' ty $ Forall_Repr_with_Context $
go ctx' $ \ty (Forall_Repr_with_Context repr) ->
k' ty $ Forall_Repr_with_Context $
\(_ `Context_Alt_Next` c') -> repr c'
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 1 ast
AST "app" asts ->
case asts of
Just Refl ->
k ty_res $ Forall_Repr_with_Context $
\c -> lam c `app` arg_actual c
- Nothing -> Left $ error_lambda_lift $
+ Nothing -> Left $ error_expr $
Error_Expr_Fun_Argument_mismatch
(Exists_Type ty_arg_expected)
(Exists_Type ty_arg_actual) ast
- Nothing -> Left $ error_lambda_lift $
+ Nothing -> Left $ error_expr_lift $
Error_Expr_Lambda_Not_a_lambda ast
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Type (error_type_lift $
Error_Type_Fun_Wrong_number_of_arguments 2 ast) ast
AST "inline" asts -> lambda_from asts inline
AST "let_lazy" asts -> let_from asts let_lazy
_ -> Left $
case hbool :: HBool (Is_Last_Expr (Expr_Lambda lam root) root) of
- HTrue -> error_expr_lift $ Error_Expr_Unsupported ast
- HFalse -> error_expr_lift $ Error_Expr_Unsupported_here ast
+ HTrue -> error_expr $ Error_Expr_Unsupported ast
+ HFalse -> error_expr $ Error_Expr_Unsupported_here ast
where
lambda_from asts
(lam::forall repr arg res. Sym_Lambda lam repr
(Proxy::Proxy (Type_Root_of_Expr root))
ast_ty_arg
(Right . Exists_Type) of
- Left err -> Left $ error_lambda_lift $ Error_Expr_Type err ast
+ Left err -> Left $ error_expr $ Error_Expr_Type err ast
Right (Exists_Type (ty_arg::Type_Root_of_Expr root h_arg)) ->
expr_from (Proxy::Proxy root)
(Var name ty_arg `Context_Alt_Next` ctx) ast_body $
Forall_Repr_with_Context $
\c -> lam $
\arg -> res (arg `Context_Alt_Next` c)
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 3 ast
let_from asts
(let_::forall repr var res. Sym_Lambda lam repr
k ty_res $ Forall_Repr_with_Context $
\c -> let_ (var c) $
\arg -> res (arg `Context_Alt_Next` c)
- _ -> Left $ error_lambda_lift $
+ _ -> Left $ error_expr $
Error_Expr_Fun_Wrong_number_of_arguments 3 ast
- error_lambda_lift
- :: Error_Expr_Lambda (Error_of_Type AST (Type_Root_of_Expr root)) (Type_Root_of_Expr root) AST
+ error_expr
+ :: Error_Expr (Error_of_Type AST (Type_Root_of_Expr root)) (Type_Root_of_Expr root) AST
-> Error_of_Expr AST root
- error_lambda_lift = error_expr_lift
+ error_expr = error_expr_lift
-- * Type 'Error_Expr_Lambda'
-data Error_Expr_Lambda err_ty ty ast
+data Error_Expr_Lambda ast
= Error_Expr_Lambda_Not_a_lambda ast
| Error_Expr_Lambda_Var_unbound Var_Name ast
- | Error_Expr_Fun_Wrong_number_of_arguments Int ast
- | Error_Expr_Fun_Argument_mismatch (Exists_Type ty) (Exists_Type ty) ast
- | Error_Expr_Type err_ty ast
deriving (Eq, Show)
stability: experimental
synopsis: Demo of Typed Tagless-Final Higher-Order Extensible DSL
tested-with: GHC==7.10.3
-version: 1.20160930
+version: 1.20161002
Source-Repository head
location: git://git.autogeree.net/lol