idris - Data Type Encompassing Two Sum Types? -


given these 2 sum types:

data foo = int | b string data bar = c int | d string 

i'd define function returns either (foo or bar) string.

so, attempted make:

data higher = foo | bar

but failed compile:

*adt> :r type checking ./adt.idr adt.idr:3:6:main.foo defined adt.idr:4:6:main.bar defined 

how can create higher data type, consists of foo or bar?

yes can indeed!

data foo = int | b string data bar = c int | d string  data higher : type     injfoo : foo -> higher     injbar : bar -> higher 

now can injfoo (b "hello") or injbar (c 5).


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -