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

Ruben Astudillo ruben.astud at gmail.com
Thu Sep 1 22:54:39 UTC 2022


On 01-09-22 16:33, Dominik Schrempf wrote:
> Chiming in here, maybe I missed something. Liquid Haskell is great, but in this
> case, in my opinion, easier is better:
> 
> newtype LeftFoo = LeftFoo !Int
> 
> newtype RightFoo = RightFoo !Char
> 
> data Foo = LFoo LeftFoo | RFoo RightFoo – Probably with strictness annotations.
> 
> isLeftFoo :: Foo -> Bool
> isLeftFoo (LFoo _) = True
> isLeftFoo _ = False
> 
> takesOnlyLeftFoo :: LeftFoo -> Int
> takesOnlyLeftFoo (LeftFoo i) = i
> 
> Dominik

Chiming in here too. I do this all the time if the subpart is to be used on
2 or more places. Easiest way to do this without extensions.

-- 
Rubén. (pgp: 1E88 3AC4 89EB FA22)



More information about the Haskell-Cafe mailing list