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

Bryan Richter bryan at haskell.foundation
Wed Nov 30 15:25:35 UTC 2022


Also, you can simplify the "map pure (...)" by using `elements` :)

https://hackage.haskell.org/package/QuickCheck-2.14.2/docs/Test-QuickCheck.html#v:elements

On Wed, Nov 30, 2022 at 5:23 PM Brandon Allbery <allbery.b at gmail.com> wrote:
>
> 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
> _______________________________________________
> 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.


More information about the Haskell-Cafe mailing list