Skip to content

Instantly share code, notes, and snippets.

@fragamus
Last active September 19, 2018 04:47
Show Gist options
  • Save fragamus/588c2ccf7f04f4897cf62ed4842ed1eb to your computer and use it in GitHub Desktop.
Save fragamus/588c2ccf7f04f4897cf62ed4842ed1eb to your computer and use it in GitHub Desktop.
Existential
{-# LANGUAGE GADTs #-}
import Data.Some
data ZeroOneTwo a where
Zero :: ZeroOneTwo ()
One :: Int -> ZeroOneTwo Int
Two :: (Int,Int) -> ZeroOneTwo Int
getSome :: Some ZeroOneTwo
getSome = This $ Two (3,10)
useSome :: Some ZeroOneTwo -> Int
useSome (This Zero) = 5
useSome (This (One (x))) = 6
useSome (This (Two (x,y))) = x+y
main = do
let c = getSome
let d = useSome c
print d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment