<div dir="ltr"><div>I made a TH function earlier this year to produce types for constructors:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">data Foo = LeftFoo !Int | RightFoo !Char<br>    deriving Show<br><br>$(constructorType 'LeftFoo)<br>deriving instance Show LeftFooC</span></div><div><br></div><div>In a repl you can see it generates a type with a single constructor, an introducer, and an eliminator.<br></div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">*Main> :browse<br>type Foo :: *<br>data Foo = LeftFoo !Int | RightFoo !Char<br>type LeftFooC :: *<br>data LeftFooC = LeftFooC Int<br>introLeftFooC :: Foo -> Maybe LeftFooC<br>elimLeftFooC :: LeftFooC -> Foo<br></span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">*Main> introLeftFooC (RightFoo 'a')<br>Nothing<br></span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">*Main> introLeftFooC (LeftFoo 123)<br>Just (LeftFooC 123)<br></span></div><div style="margin-left:40px"><span style="font-family:monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace">*Main> elimLeftFooC $ LeftFooC 456<br>LeftFoo 456</span></div><div><div><br></div><div>If you find that useful, I ripped it out of my other repo and pasted it here: <a href="https://gist.github.com/plredmond/5fd15fb388647b248de87693542d2adb">https://gist.github.com/plredmond/5fd15fb388647b248de87693542d2adb</a></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 1, 2022 at 3:54 PM Ruben Astudillo <<a href="mailto:ruben.astud@gmail.com" target="_blank">ruben.astud@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 01-09-22 16:33, Dominik Schrempf wrote:<br>
> Chiming in here, maybe I missed something. Liquid Haskell is great, but in this<br>
> case, in my opinion, easier is better:<br>
> <br>
> newtype LeftFoo = LeftFoo !Int<br>
> <br>
> newtype RightFoo = RightFoo !Char<br>
> <br>
> data Foo = LFoo LeftFoo | RFoo RightFoo – Probably with strictness annotations.<br>
> <br>
> isLeftFoo :: Foo -> Bool<br>
> isLeftFoo (LFoo _) = True<br>
> isLeftFoo _ = False<br>
> <br>
> takesOnlyLeftFoo :: LeftFoo -> Int<br>
> takesOnlyLeftFoo (LeftFoo i) = i<br>
> <br>
> Dominik<br>
<br>
Chiming in here too. I do this all the time if the subpart is to be used on<br>
2 or more places. Easiest way to do this without extensions.<br>
<br>
-- <br>
Rubén. (pgp: 1E88 3AC4 89EB FA22)<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" 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>