[Haskell-cafe] Re: ambiguous partially defined type problem

Brian Hulley brianh at metamilk.com
Fri Sep 15 11:31:57 EDT 2006

Maarten wrote:
> Only update (see code below) is a bit ugly (I have no idea why I need
> fixCastUpdate)
> class (Show a, Typeable a) => ICustom a where
>    update :: a -> (forall b. (ICustom b) => b -> b) -> a
>    update a f = f a
> instance ICustom Node where
>    getVal (Node n) f = getVal n f
>    update (Node n) f = Node (update n f)
> updateM :: forall a b. (ICustom a, ICustom b) => (a -> b) ->
> NodeState () updateM f = do
>    s <- get
>    let s' = update s (fixCastUpdate f)
>    put s'

Hi Maarten -
Looking at this again, I wonder if the following changes would work:

    -- this change is not strictly necessary
    update :: a -> (a -> a) -> a

    updateM :: (forall a. ICustom a => a -> a) -> NodeState ()
    updateM f = do
        s <- get
        let s' = update s f
        put s'

I think the reason why fixCastUpdate was needed in your original definition 
of updateM is because the type of f seems to be too general (a->b) compared 
to the type of f in the update method of ICustom (b->b)

Regards, Brian.
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.


More information about the Haskell-Cafe mailing list