Created
April 24, 2014 04:49
-
-
Save munro/11241890 to your computer and use it in GitHub Desktop.
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 FlexibleInstances #-} | |
import GHC.Float | |
data LangVariable = LangString String | LangNumber Double | LangNull deriving Show | |
class LangCoercion a where | |
toLangVariable :: a -> LangVariable | |
instance LangCoercion String where | |
toLangVariable a = LangString a | |
instance LangCoercion Double where | |
toLangVariable a = LangNumber a | |
instance LangCoercion Float where | |
toLangVariable a = LangNumber $ float2Double a | |
instance LangCoercion (Maybe a) where | |
toLangVariable (Just n) = toLangVariable n | |
-- ^ Error | |
-- No instance for (LangCoercion a) | |
-- arising from a use of `toLangVariable' | |
-- Possible fix: | |
-- add (LangCoercion a) to the context of the instance declaration | |
-- In the expression: toLangVariable n | |
-- In an equation for `toLangVariable': | |
-- toLangVariable (Just n) = toLangVariable n | |
-- In the instance declaration for `LangCoercion (Maybe a)' | |
toLangVariable (Nothing) = LangNull |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment