Unprincipled defaults

Richard Eisenberg rae at cs.brynmawr.edu
Fri Sep 2 16:39:04 UTC 2016


I feel like I must be missing something, but what's wrong with

> class Semigroup1 f where
>   op :: f a -> f a -> f a
> 
>   default op :: Monoid (f a) => f a -> f a -> f a
>   op = (<>)

? Does that do what you like?

Richard


> On Sep 1, 2016, at 11:15 PM, David Feuer <david.feuer at gmail.com> wrote:
> 
> On occasion, it can be useful to have default definitions that don't typecheck even with DefaultSignatures. It would be nice to be able to use them anyway. For example, if we have
> 
> class Semigroup1 f where
>   op :: f a -> f a -> f a
> 
> then we could, hypothetically, give a default definition for (<>):
> 
>   default (<>) :: Semigroup1 f => f a -> f a -> f a
>   (<>) = op
> 
> But we can't give a default definition
> 
>   op = (<>)
> 
> because there's no way to write its signature. However, for any F with
> 
> instance Semigroup (F a) where ...
> 
> the definition op = (<>) is perfectly fine.
> 
> Would it be possible to offer a completely wild defaulting mechanism allowing *any expression* as a default, and only checking its type and compiling it when it's actually used?
> 
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160902/a53c219c/attachment.html>


More information about the ghc-devs mailing list