mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-19 09:12:34 +03:00
31 lines
733 B
Idris
31 lines
733 B
Idris
import Language.Reflection
|
|
|
|
%language ElabReflection
|
|
|
|
fc : FC
|
|
fc = EmptyFC
|
|
|
|
mkEnum : (name : String) -> (cons : List String) -> Elab ()
|
|
mkEnum name cons =
|
|
let enumDecl = IData EmptyFC Public Nothing dat
|
|
in declare [enumDecl]
|
|
where enumName : Name
|
|
enumName = UN $ Basic name
|
|
|
|
mkCon : String -> ITy
|
|
mkCon n = MkTy EmptyFC EmptyFC (UN $ Basic n) (IVar EmptyFC enumName)
|
|
|
|
dat : Data
|
|
dat = MkData EmptyFC enumName (Just (IType EmptyFC)) [] (map mkCon cons)
|
|
|
|
%runElab mkEnum "FooBar" ["Foo","Bar"]
|
|
|
|
eqFooBar : FooBar -> FooBar -> Bool
|
|
eqFooBar Foo Foo = True
|
|
eqFooBar Bar Bar = True
|
|
eqFooBar _ _ = False
|
|
|
|
main : IO ()
|
|
main = printLn (eqFooBar Foo Foo)
|
|
>> printLn (eqFooBar Bar Foo)
|