Created
October 11, 2014 14:52
-
-
Save FranklinChen/43fabea3d102742fc7ba to your computer and use it in GitHub Desktop.
"" + 0
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
{-# LANGUAGE OverloadedStrings #-} | |
import Data.String | |
data Value = VInt Int | |
| VString String | |
-- In order to hide the unitype details from the user. | |
instance Show Value where | |
show (VInt i) = show i | |
show (VString s) = show s | |
instance IsString Value where | |
fromString = VString | |
instance Num Value where | |
fromInteger = VInt . fromInteger | |
VInt i + VInt j = VInt $ i + j | |
VString s + VInt j = VString $ s ++ show j | |
-- etc. | |
-- | Be like other languages. | |
-- | |
-- >>> foo | |
-- "0" | |
foo :: Value | |
foo = "" + 0 | |
main :: IO () | |
main = print foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment