Created
August 6, 2014 22:32
-
-
Save skatenerd/a6ad27a8fc3bf1510fe8 to your computer and use it in GitHub Desktop.
return type polymorphism
This file contains hidden or 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
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