I'm trying to deriving Show, Eq, Ord etc in Idris, but none of the following trials works:
trail #1:
data Expr =
Lit Int
| Neg Expr
| Add Expr Expr
deriving (Show)
got:
deriving.idr:5:15-18:
|
5 | deriving (Show)
| ~~~~
When checking type of Main.Add:
Type mismatch between
Type -> Type (Type of Show)
and
Type (Expected type)
trail #2:
data Expr =
Lit Int
| Neg Expr
| Add Expr Expr
deriving (Show _)
got:
*deriving> Lit 1
Lit 1 : Expr
*deriving> Add (Lit 1) (Lit 1)
(input):Can't infer argument ty to Add, Can't infer argument deriving to Add
trail #3:
data Expr =
Lit Int
| Neg Expr
| Add Expr Expr
deriving (Show Expr)
got:
*deriving> Lit 1
Lit 1 : Expr
*deriving> Add (Lit 1) (Lit 1)
(input):Can't infer argument deriving to Add
I have searched the keyword deriving
on http://docs.idris-lang.org/ and google, and even in the idris-dev repo under test/ directory, but there is no demo for the usage of deriving in idris. Anyone can help?
deriving
syntax. There is only elaborator reflection, which is like Template Haskell. – Masinissaderiving
syntax, it passed the syntax checking, so I think there must be something similar ? – MyrillaExpr = ... | Add (Expr) (Expr) (deriving) (Show)
, wherederiving
is just a (existential) type variable. You get an error because constructor field types must beType
s, butShow
isn't. If you remove theShow
"field" you get a constructorAdd : {deriving : Type} -> Expr -> Expr -> deriving -> Expr
– Masinissa