[Haskell-cafe] How to create a list of each constructor value
s9gf4ult
s9gf4ult at gmail.com
Wed Nov 30 17:43:58 UTC 2022
You can use `generic-arbitrary` like this
```haskell
import Test.QuickCheck.Arbitrary.Generic
data CristalK6C ...
deriving Generic
deriving (Arbitrary) via GenericArbitrary CristalK6C
```
On 30.11.2022 21:18, PICCA Frederic-Emmanuel wrote:
> Hello, I have a type like this
>
> data InputType = CristalK6C
> | MarsFlyscan
> | MarsSbs
> | SixsFlyMedH
> | SixsFlyMedV
> | SixsFlyMedVEiger
> | SixsFlyMedVS70
> | SixsFlyScanUhv
> | SixsFlyScanUhv2
> | SixsFlyScanUhvTest
> | SixsFlyScanUhvUfxc
> | SixsSbsFixedDetector
> | SixsSbsMedH
> | SixsSbsMedV
> | SixsSbsMedVFixDetector
> deriving (Eq, Show)
>
> I want to create a list of each values in order to create meaningfull error message for the user and simplify my Arbitrary instances.
> I do not want to type two time the values.
>
> instance Arbitrary InputType where
> arbitrary = oneof (map pure
> [ CristalK6C
> , MarsFlyscan
> , MarsSbs
> , SixsFlyMedH
> , SixsFlyMedV
> , SixsFlyMedVEiger
> , SixsFlyMedVS70
> , SixsFlyScanUhv
> , SixsFlyScanUhv2
> , SixsFlyScanUhvTest
> , SixsFlyScanUhvUfxc
> , SixsSbsFixedDetector
> , SixsSbsMedH
> , SixsSbsMedV
> , SixsSbsMedVFixDetector
> ]
> )
>
>
> Thanks for your help
>
> Frederic
> _______________________________________________
> 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/20221130/1989baac/attachment.html>
More information about the Haskell-Cafe
mailing list