Skip to content

Instantly share code, notes, and snippets.

@skatenerd
Created August 6, 2014 22:32
Show Gist options
  • Save skatenerd/a6ad27a8fc3bf1510fe8 to your computer and use it in GitHub Desktop.
Save skatenerd/a6ad27a8fc3bf1510fe8 to your computer and use it in GitHub Desktop.
return type polymorphism
class WithInt c where
combinate :: Integral i => i -> c -> [(i,c)]
class RTP c where
fromNothing :: Integral i => i -> [(i,c)]
data Wut = Wut deriving (Show)
data Foo = Foo deriving (Show)
instance WithInt Wut where
combinate i w = if (i == 0)
then []
else (i,w):combinate (i - 1) w
instance RTP Wut where
fromNothing i = if (i == 0)
then []
else (i,Wut):fromNothing (i - 1)
instance RTP Foo where
fromNothing i = [(8, Foo)]
main = let wutlist :: [(Int, Wut)]
wutlist = fromNothing 7
foolist :: [(Int, Foo)]
foolist = fromNothing 7
in do
putStrLn $ show wutlist
putStrLn $ show foolist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment