Created
July 26, 2018 09:26
-
-
Save Rydgel/764cb99acf33f85e399a37799b42db6b to your computer and use it in GitHub Desktop.
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 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