Last active
May 31, 2016 23:42
-
-
Save missingfaktor/d2fbb0ff371f903ef00ca9b0515b92f4 to your computer and use it in GitHub Desktop.
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
| Prelude> newtype Dyn a = Dyn a deriving Show | |
| Prelude> data Book = Book (Dyn String) Int deriving Show | |
| Prelude> :{ | |
| Prelude| class Serialise a where | |
| Prelude| serialise :: a -> String | |
| Prelude| :} | |
| Prelude> instance Serialise Book where serialise (Book (Dyn s) i) = s ++ ":" ++ show i | |
| Prelude> | |
| Prelude> let serialisedBook = fmap serialise (\s -> Book s 32) | |
| Prelude> -- apply dynamic value when available | |
| Prelude> serialisedBook (Dyn "isbn") | |
| "isbn:32" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment