Skip to content

Instantly share code, notes, and snippets.

@pete-murphy
Created August 21, 2021 19:48
Show Gist options
  • Save pete-murphy/6513178245bfff9c43f2f157c8585609 to your computer and use it in GitHub Desktop.
Save pete-murphy/6513178245bfff9c43f2f157c8585609 to your computer and use it in GitHub Desktop.
Arbitrary for custom ADT
module Main where
import Prelude
import Effect (Effect)
import Effect.Class.Console as Console
import Data.Generic.Rep (class Generic)
import Data.Show.Generic as Show.Generic
import Test.QuickCheck.Arbitrary (class Arbitrary)
import Test.QuickCheck.Arbitrary as Arbitrary
import Test.QuickCheck.Gen (Gen)
import Test.QuickCheck.Gen as Gen
data FooBarBaz a b c
= Foo a
| Bar b
| Baz c
derive instance Generic (FooBarBaz a b c) _
instance (Show a, Show b, Show c) => Show (FooBarBaz a b c) where
show = Show.Generic.genericShow
instance (Arbitrary a, Arbitrary b, Arbitrary c) => Arbitrary (FooBarBaz a b c) where
arbitrary = Arbitrary.genericArbitrary
main :: Effect Unit
main = do
sample <- Gen.randomSample (Arbitrary.arbitrary :: Gen (FooBarBaz Number String Int))
Console.logShow sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment