Why no multiple default method implementations?
José Pedro Magalhães
jpm at cs.uu.nl
Thu Nov 24 16:46:29 CET 2011
Hi Bas,
On Thu, Nov 24, 2011 at 09:23, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> Hello,
>
> Now that we have DefaultSignatures, why is it not allowed to have
> multiple default method implementations, as in:
>
> {-# LANGUAGE DefaultSignatures #-}
>
> class Foo a where
> foo :: a
> foo = error "foo"
>
> default foo :: Num a => a
> foo = 1
>
> GHC complains: "Conflicting definitions for `foo'"
>
> The following use of multiple default signatures also gives the same error:
>
> class Foo a where
> foo :: a
>
> default foo :: Fractional a => a
> foo = 0.5
>
> default foo :: Num a => a
> foo = 1
>
> Couldn't GHC always pick the most specific default method, just as it
> does with instances when OverlappingInstances is enabled?
>
As far as I understand, GHC never looks at the context to decide which
instance is applicable:
http://www.haskell.org/ghc/docs/7.2.1/html/users_guide/type-class-extensions.html#instance-overlap
Your instances above are duplicates.
Cheers,
Pedro
> Regards,
>
> Bas
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20111124/3eec9809/attachment.htm>
More information about the Glasgow-haskell-users
mailing list