<div dir="auto">One downside of this *particular* formulation is that it doesn't play well with Coercible.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 30, 2022, 9:31 AM Olaf Klinke <<a href="mailto:olf@aatal-apotheke.de">olf@aatal-apotheke.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Café,<br>
<br>
Is there prior art/existing packages for the following? Is it maybefunctional programming folklore? Is it a sign of bad program design? <br>
Sometimes I feel the need to selectively allow or disallow alternatives<br>
in a sum type. That is, suppose we have a sum type<br>
<br>
data Foo = LeftFoo !A | RightFoo !B<br>
<br>
and at some places in the program we want the type system to enforce<br>
that only the constructor LeftFoo can be used. My solution would be to<br>
use a strict version of Data.Functor.Const and make the type higher<br>
rank:<br>
<br>
newtype Const' a b = Const' !a<br>
-- Const' Void b ~ Void<br>
-- Const' ()   b ~ ()<br>
<br>
data Foo' f = LeftFoo' !A | RightFoo' !(f B)<br>
type Foo = Foo' Identity<br>
type LeftFoo = Foo' (Const' Void) -- can not construct a RightFoo'<br>
<br>
The advantage over defining LeftFoo as an entirely different type is<br>
that Foo and LeftFoo can share functions operating entirely on the left<br>
option. <br>
<br>
Olaf<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>