Created
July 22, 2016 21:55
-
-
Save berewt/9f1f735cd0a47847981ab7c8f3bfa39b to your computer and use it in GitHub Desktop.
Union type in Idris
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Data.Union | |
import Data.Vect | |
data Sum : {n: Nat} -> Vect n Type -> Type where | |
isA: t -> {auto e: Elem t ts} -> Sum ts | |
data Orange = AnOrange String | |
data Apple = AnApple String | |
fruit : Type | |
fruit = Sum [Orange, Apple] | |
-- Usage: | |
-- the fruit isA $ AnOrange "foo" | |
-- the fruit isA $ AnApple "bar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment