Created
October 20, 2014 22:03
-
-
Save pjrt/d2c2339e5bc0c93f6e23 to your computer and use it in GitHub Desktop.
Returning functions and values restricted by typeclasses
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 Writable a where | |
| write :: a -> String | |
| data Box = Box String | |
| data Hax = Hax String | |
| instance Writable Hax where | |
| write (Hax str) = str | |
| instance Writable Box where | |
| write (Box str) = str | |
| func :: Writable a => Int -> (a -> String, a) | |
| func compare = if compare > 0 | |
| then (write, Box (show compare)) | |
| else (write, Hax (show compare)) | |
| main = do | |
| let (f, v) = func 1 | |
| putStrLn $ f v |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work. Error is: