Skip to content

Instantly share code, notes, and snippets.

@xenophobia
Created March 4, 2015 00:05
Show Gist options
  • Save xenophobia/69d295b0987c906fcd37 to your computer and use it in GitHub Desktop.
Save xenophobia/69d295b0987c906fcd37 to your computer and use it in GitHub Desktop.
data T a = T {element :: a, element2 :: a, element3 :: String} deriving (Show)
class F a where
mes :: a -> String
instance F Int where mes _ = "Int"
instance F Double where mes _ = "Double"
mkDefaultT :: (F a, Num a) => a -> T a
mkDefaultT x = T x x (mes x)
defaultT :: (F a, Num a) => T a
defaultT = mkDefaultT 0
-- error!
modifiedT :: T Double
modifiedT = defaultT {
element = 1.0 :: Double
, element2 = 0.0 :: Double
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment