Skip to content

Instantly share code, notes, and snippets.

@FranklinChen
Created October 11, 2014 14:52
Show Gist options
  • Save FranklinChen/43fabea3d102742fc7ba to your computer and use it in GitHub Desktop.
Save FranklinChen/43fabea3d102742fc7ba to your computer and use it in GitHub Desktop.
"" + 0
{-# 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