Access to class defaults and derived instances

David Feuer david.feuer at gmail.com
Mon Aug 24 12:52:31 UTC 2015


I'm not sure if it really could work out at all. The concept is that I want
the newtype wrapper to get the class defaults the wrapped type would have
gotten (whether the wrapped type is actually a class instance or not).
On Aug 24, 2015 8:39 AM, "Richard Eisenberg" <eir at cis.upenn.edu> wrote:

> I have a hard time fully understanding this request without more context.
> But I do think I understand the last paragraph. And it seems bound to
> create class incoherence. What if someone else *does* write that orphan
> instance you're avoiding writing?
>
> Richard
>
> On Aug 22, 2015, at 12:54 PM, David Feuer <david.feuer at gmail.com> wrote:
>
> From time to time, a library lacks an instance for something that I want.
> For example, I may need to convert
>
> data Foo = Bar (Vector Baz)
>
> to FishFood, but (to avoid unreasonable dependencies) Vector doesn't have
> a ToFishFood instance, so I can't just write
>
> instance ToFishFood Foo
>
> and (using Generic magic) be done with it. Instead, I must write the
> instance completely by hand, which could be painful. I *could* write an
> orphan instance, but orphans are evil.
>
> What I wish I could do:
>
> newtype Vec a = Vec (Vector a)
>
> instance ToFishFood a => (newtype Vec) a where
>   -- if needed
>   toFishFood (v :: Vector a) = ...
>
> That is, I want to write a super-secret orphan instance for Vector and
> transfer it to Vec via GND precisely when it is legal to do so. The secret
> instance could itself be derived (if the constructors are visible) or could
> make use of default member definitions.
> _______________________________________________
> 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/20150824/4cdeef3a/attachment.html>


More information about the ghc-devs mailing list