Proposal: GHC.Generics marked UNSAFE for SafeHaskell

Edward Kmett ekmett
Mon Oct 7 20:12:59 UTC 2013


I have no particular opinions on the internals of LVish.

I do have concern than your supplied Generic for Set seems rather borked
though, so I felt I should explain the issue lest someone take it as a
model for how to define a custom Generic! =)

A real valid 'virtual' Rep (Set a) would be a fair bit more complicated
with something like

instance Generic Set where
    type Rep (Set a) = D1 D_Set (C1 C_fromList (S1 NoSelector (Rec0 [a]))
    to (M1 (M1 (M1 (K1 as))) = fromList as
    from as = M1 (M1 (M1 (K1 (toList as)

instance Generic1 Set where
    type Rep1 Set = D1 D1_Set (C1 C1_fromList (S1 NoSelector (Rec1 []))
    ...

with a custom Datatype instances D_Set, D1_Set and custom virtual
Constructor instances C_fromList and C1_fromList.

Otherwise it won't deal correctly with any code out there that was written
to assume a properly constructed Generic.

Headaches like that are why few of us ever implement Generic or Generic1 by
hand. ;)

Actually, I can't think of anyone else who has bothered. I was forced to
figure it out back when Generic1 deriving was broken.

-Edward


On Mon, Oct 7, 2013 at 3:28 PM, adam vogt <vogt.adam at gmail.com> wrote:

> On Mon, Oct 7, 2013 at 1:33 PM, Ryan Newton <rrnewton at gmail.com> wrote:
> > Again, my use-case (closed/safe Eq & Ord instances) is a few steps
> removed
> > from this Generics business and I don't feel strongly about how it gets
> > done.  But having *SOME* way of doing it will be a massive boon to my
> lab's
> > particular effort at maximizing the abilities of guaranteed-Safe
> > deterministic parallelism in Haskell.  Further, I think anyone else who
> > tries to do something in SafeHaskell that depends on guaranteeing a
> > closed/controlled set of instances (SafeEq, SafeOrd but also others)
> based
> > on GHC.Generics will *also* find this change useful.
>
> Hi,
>
> In containers we have Data instances "This instance preserves data
> abstraction at the cost of inefficiency". Generic is a more modern way
> to address the same problem. This Generic instance for Set is just a
> more convenient way to use Set.toList/Set.fromList
> <http://lpaste.net/94028>, which are -XSafe functions right?
>
> For your problem I suggest using template-haskell to write your
> "SafeEq" "SafeOrd" instances. It will let you access unexported
> constructors too, which means people using LVish can maintain their
> abstractions for everybody except LVish. My understanding is that the
> proposed changes to ghc/Generic would mean that all data used with
> LVish would have to expose it's implementation to everybody through
> the derived Generic instance.
>
> Regards,
> Adam
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20131007/f98e1655/attachment.html>




More information about the Libraries mailing list