mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-20 18:21:47 +03:00
c3ec522077
Co-authored-by: G. Allais <guillaume.allais@ens-lyon.org> Co-authored-by: stefan-hoeck <hock@zhaw.ch>
31 lines
726 B
Idris
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)
|