[Haskell-cafe] How to create a list of each constructor value

Brandon Allbery allbery.b at gmail.com
Wed Nov 30 15:22:49 UTC 2022


Derive Enum and Bounded and use [minBound .. maxBound] :: [InputType]

On Wed, Nov 30, 2022 at 10:19 AM PICCA Frederic-Emmanuel
<frederic-emmanuel.picca at synchrotron-soleil.fr> 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.



-- 
brandon s allbery kf8nh
allbery.b at gmail.com


More information about the Haskell-Cafe mailing list