Idris2/tests/idris2/reflection014/refdecl.idr
Balazs Komuves c3ec522077
[ fix #1404 ] Totality annotation for data type definitions (#2179)
Co-authored-by: G. Allais <guillaume.allais@ens-lyon.org>
Co-authored-by: stefan-hoeck <hock@zhaw.ch>
2021-12-08 16:08:26 +00:00

31 lines
726 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 (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)