Skip to content

Instantly share code, notes, and snippets.

@Rydgel
Created July 26, 2018 09:26
Show Gist options
  • Save Rydgel/764cb99acf33f85e399a37799b42db6b to your computer and use it in GitHub Desktop.
Save Rydgel/764cb99acf33f85e399a37799b42db6b to your computer and use it in GitHub Desktop.
module Main where
newtype HasName a =
HasName (a -> String)
data A = A deriving (Show)
data B = B deriving (Show)
data C = C deriving (Show)
aName :: HasName A
aName = HasName $ const "A"
bName :: HasName B
bName = HasName $ const "B"
cName :: HasName C
cName = HasName $ const "C"
dispatch :: Int -> HasName A -> HasName B -> HasName (Either A B)
dispatch 0 (HasName a) _ = HasName (\(Left A) -> a A)
dispatch 1 _ (HasName b) = HasName (\(Right B) -> b B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment