Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lambda-buffers-compiler/lambda-buffers-compiler.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ common common-language
DeriveLift
DeriveTraversable
DerivingStrategies
DerivingVia
DoAndIfThenElse
DuplicateRecordFields
EmptyCase
Expand Down Expand Up @@ -94,12 +95,15 @@ library
build-depends:
, containers >=0.6.5.1
, freer-simple >=1.2
, generic-arbitrary
, generic-lens >=2.2
, lambda-buffers-compiler-pb >=0.1.0.0
, mtl >=2.2
, parsec >=3.1
, prettyprinter >=1.7
, proto-lens >=0.7
, QuickCheck >=2.14
, quickcheck-instances >=0.3
, text >=1.2

exposed-modules:
Expand Down Expand Up @@ -147,16 +151,17 @@ test-suite tests
, lambda-buffers-compiler
, lambda-buffers-compiler-pb >=0.1
, proto-lens >=0.7
, QuickCheck >=2.14
, tasty >=1.4
, tasty-hunit >=0.10
, tasty-quickcheck >=0.10
, text >=1.2

other-modules:
Test.KindCheck
Test.Samples
Test.Samples.Proto.CompilerInput
Test.Samples.Proto.Helpers
Test.Samples.Proto.Module
Test.Samples.Proto.SourceInfo
Test.Samples.Proto.TyDef
Test.TypeClassCheck
Test.Utils.CompilerInput
Test.Utils.Constructors
Test.Utils.Module
Test.Utils.SourceInfo
Test.Utils.TyDef
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module LambdaBuffers.Compiler.KindCheck.Type (

import LambdaBuffers.Compiler.KindCheck.Variable (Variable (LocalRef))
import Prettyprinter (Doc, Pretty (pretty), parens, (<+>))
import Test.QuickCheck (Arbitrary, Gen, arbitrary, oneof, sized)

data Type
= Var Variable
Expand All @@ -32,3 +33,16 @@ instance Pretty Type where
Var a -> pretty a
App t1 t2 -> parens $ show' t1 <+> show' t2
Abs a t1 -> parens $ "λ" <> pretty a <> "." <> show' t1

instance Arbitrary Type where
arbitrary = sized f
where
f :: Integral a => a -> Gen Type
f n
| n <= 0 = Var <$> arbitrary
| otherwise =
oneof
[ Var <$> arbitrary
, App <$> f (n `div` 2) <*> f (n `div` 2)
, Abs <$> arbitrary <*> f (n - 1)
]
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
module LambdaBuffers.Compiler.KindCheck.Variable (Variable (LocalRef, ForeignRef), Atom) where

import Data.Text (Text)
import GHC.Generics (Generic)
import Prettyprinter (Pretty (pretty), concatWith)
import Test.QuickCheck (Arbitrary)
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary (GenericArbitrary))
import Test.QuickCheck.Instances.Text ()

type Atom = Text

data Variable
= LocalRef Text
| ForeignRef [Text] Text
deriving stock (Eq, Ord, Show)
deriving stock (Eq, Ord, Show, Generic)
deriving (Arbitrary) via GenericArbitrary Variable

instance Pretty Variable where
pretty = \case
Expand Down
Loading