Skip to content

Instantly share code, notes, and snippets.

@berewt
Created July 22, 2016 21:55
Show Gist options
  • Save berewt/9f1f735cd0a47847981ab7c8f3bfa39b to your computer and use it in GitHub Desktop.
Save berewt/9f1f735cd0a47847981ab7c8f3bfa39b to your computer and use it in GitHub Desktop.
Union type in Idris
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