Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 7 additions & 2 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,14 @@ 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
, text >=1.2

exposed-modules:
Expand All @@ -115,6 +118,7 @@ library
LambdaBuffers.Compiler.ProtoCompat
LambdaBuffers.Compiler.ProtoCompat.Types
LambdaBuffers.Compiler.TypeClassCheck
Orphan.Text

hs-source-dirs: src

Expand Down Expand Up @@ -144,16 +148,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.Samples.Proto.Utils
Test.TypeClassCheck
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 Orphan.Text ()
import Prettyprinter (Pretty (pretty), concatWith)
import Test.QuickCheck (Arbitrary)
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary (GenericArbitrary))

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