[Haskell-cafe] ambiguous partially defined type problem
Maarten
maarten at snowlion.nl
Thu Sep 14 10:20:46 EDT 2006
Dear all,
For a project involving I use some partially defined node (in this case
a simple record, in my project state transformers) in which the defined
part is common to all nodes, and the custom part is different for each
node. They have to become anonymous so I can put them in a list of
connections from each node to another.
For some reason GHC complains of 'ambigous type variable' in the code
below. The thing is, part of the code may be undefined, but since I'm
(explicitly) not using that part, why would GHC care? Are there other
solutions to this problem? Any pointers or comments appreciated. Thanks.
Maarten
(This code is just some dummy code that contains the essence of the
problem. I posted the complete code with piggy bagged state transformers
in active objects on haskell at haskell.org, but that is rather long and
this seems to be the correct mailing list).
-- data structure with custom and common part
data Node cust = Node cust Common
deriving (Show,Typeable)
-- anonymous data structure to put use in list
data AN = forall ar. (Show ar, Typeable ar) => AN ar
instance Show AN where
show (AN an) = "AN (" ++ show an ++ ")"
-- common part
data Common = Common Integer
deriving (Show,Typeable)
data Custom = Custom Integer
deriving (Show,Typeable)
data Custom2 = Custom2 Integer
deriving (Show,Typeable)
-- extract common part, ignoring type of custom part
getCommon :: forall gc. (Node gc) -> Common
getCommon (Node cust com) = com
main = do
let a = AN (Node (Custom 5) (Common 10))
let b = case a of (AN a') -> getCommon (case (cast a') of Just a''
-> a'')
putStrLn $ "ok:" ++ show b
More information about the Haskell-Cafe
mailing list