[Haskell-cafe] selectively allow alternatives in a sum type

David Feuer david.feuer at gmail.com
Wed Aug 31 22:25:32 UTC 2022


To avoid actually realizing those boring fields in memory, use an unlifted
newtype.

type VoidUnit# :: TYPE ('TupleRep '[])
newtype VoidUnit# = VoidUnit# VoidUnit#

absurd# :: VoidUnit# -> a
absurd# (VoidUnit# v) = absurd# v

Unfortunately, GHC's pattern checker isn't smart enough to see by itself
that VoidUnit# is uninhabited, even though that's pretty obvious to a human.

TTG also has coercion problems thanks to the type families. *Sigh*

On Wed, Aug 31, 2022, 4:48 PM Olaf Klinke <olf at aatal-apotheke.de> wrote:

> > Trees that grow is essentially this, but using type families.
> >
> >     data Foo ksi
> >         = LeftFoo !(XLeftFoo ksi) !A
> >         | RightFoo !(XRightFoo ksi) !B
> >
> >     type family XLeftFoo ksi :: Type
> >     type family XRightFoo ksi :: Type
> >
> > Then you can define
> >
> >     data Both
> >     type instance XLeftFoo  Both = ()
> >     type instance XRightFoo Both = ()
> >
> > or
> >
> >     data OnlyLeft
> >     type instance XLeftFoo  OnlyLeft = ()
> >     type instance XRightFoo OnlyLeft = Void
> >
> > ---
> >
> > Third option is to simply have parametrized data:
> >
> >    data Foo b
> >        = LeftFoo !A
> >        | RIghtFoo !b
> >
> >    type FooBoth = Foo B
> >    type FooOnlyLeft = Foo Void
> >
> > ---
> >
> > Sometimes I prefer a higher-kinded data approach, especially if there is
> > very little variants needed, and they are "uniform" (e.g. second variant
> > doesn't have some fields).
> > Yet, sometimes simple parameterized data is simplest approach
> > (especially as you get stuff for free by deriving Traversable!).
> >
> > On the other hand, if type is big and have many uniform extension points
> > (even if there are few different combinations), then HKD becomes
> > boilerplate heavy as well.
> > The drawback of TTG, is that writing polymorphic code (i.e. which work
> > for any or some `ksi`s) is not very fun: a lot of equality constraints
> etc.
> >
> > - Oleg
>
> So I re-discovered Trees that Grow sans the trick of using type
> families to name particular combinations of parameters. Hooray Najd,
> and thanks Oleg for bringing this up.
>
> Olaf
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20220831/1a853ee4/attachment.html>


More information about the Haskell-Cafe mailing list