existentials'ы

Jun 15, 2007 20:06

Похоже я недостаточно хорошо понял existentials'ы, либо просто туплю ...

{-# OPTIONS_GHC -fglasgow-exts #-}
module S1 where

data B = forall a . (Show a, Read a) => BC a

instance Show B where -- чтобы видеть
show (BC a) = "BC " ++ show a

instance Read B where
readsPrec _ input =
[(BC val, tailString)] where -- 11-ая строка
withValue = drop (length "BC ") input
[(val, tailString)] = readsPrec 1 withValue -- 13-ая строка

Prelude> :r
[1 of 1] Compiling S1 ( s1.hs, interpreted )

s1.hs:11:4:
Ambiguous type variable `t' in the constraints:
`Show t' arising from use of `S1.BC' at s1.hs:11:4-9
`Read t' arising from use of `readsPrec' at s1.hs:13:25-45
Probable fix: add a type signature that fixes these type variable(s)
Failed, modules loaded: none.
Prelude>
Не могу понять почему ambiguous.

haskell

Previous post Next post
Up