Skip to content

Commit b7c5764

Browse files
initial commit
1 parent 019895c commit b7c5764

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+17602
-0
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Haskell-CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
pull_request:
8+
branches:
9+
- 'master'
10+
schedule:
11+
- cron: 0 0 * * *
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
linux:
19+
name: Haskell-CI - Linux - ${{ matrix.ghc-version }}
20+
21+
strategy:
22+
matrix:
23+
ghc-version: [latest, 9.12, "9.10", 9.8, 9.6]
24+
os: [ubuntu-24.04]
25+
fail-fast: false
26+
27+
runs-on: ${{ matrix.os }}
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: haskell-actions/setup@v2
32+
with:
33+
ghc-version: ${{matrix.ghc-version}}
34+
- uses: actions/cache/restore@v4
35+
with:
36+
key: ${{ matrix.os }}-${{ matrix.ghc-version }}-${{ github.sha }}
37+
path: ~/.cabal/store
38+
restore-keys: ${{ matrix.os }}-${{ matrix.ghc-version }}-
39+
- run: cabal build all
40+
- run: cabal test all
41+
- run: cabal haddock all
42+
- uses: actions/cache/save@v4
43+
with:
44+
key: ${{ matrix.os }}-${{ matrix.ghc-version }}-${{ github.sha }}
45+
path: ~/.cabal/store

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ cabal.project.local
2121
cabal.project.local~
2222
.HTF/
2323
.ghc.environment.*
24+
*.*.sw*

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Version history for `constrained-generators`
2+
3+
## This package is not being released yet.

bench/Constrained/Bench.hs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE FlexibleContexts #-}
3+
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE MultiParamTypeClasses #-}
5+
{-# LANGUAGE TypeApplications #-}
6+
{-# LANGUAGE TypeFamilies #-}
7+
{-# LANGUAGE TypeOperators #-}
8+
{-# LANGUAGE UndecidableInstances #-}
9+
10+
module Constrained.Bench where
11+
12+
import Constrained.API
13+
import Control.DeepSeq
14+
import Criterion
15+
import Data.Map (Map)
16+
import Data.Set (Set)
17+
import Data.Tree
18+
19+
benchmarks :: Benchmark
20+
benchmarks =
21+
bgroup
22+
"constrained"
23+
[ benchSpec 10 30 "TrueSpec@Map" (trueSpec :: Specification (Map Int Int))
24+
, benchSpec 10 30 "TrueSpec@[]" (trueSpec :: Specification [Int])
25+
, benchSpec 10 30 "TrueSpec@Set" (trueSpec :: Specification (Set Int))
26+
, benchSpec
27+
10
28+
30
29+
"TrueSpec@Tree"
30+
(giveHint (Nothing, 30) <> trueSpec :: Specification (Tree Int))
31+
, benchSpec 10 30 "roseTreeMaybe" roseTreeMaybe
32+
, benchSpec 10 30 "listSumPair" listSumPair
33+
]
34+
35+
roseTreeMaybe :: Specification (Tree (Maybe (Int, Int)))
36+
roseTreeMaybe = constrained $ \t ->
37+
[ forAll' t $ \mp ts ->
38+
forAll ts $ \t' ->
39+
onJust mp $ \p ->
40+
onJust (rootLabel_ t') $ \p' ->
41+
fst_ p' ==. snd_ p
42+
, forAll' t $ \mp _ -> isJust mp
43+
, genHint (Nothing, 10) t
44+
]
45+
46+
listSumPair :: Specification [(Int, Int)]
47+
listSumPair = constrained $ \xs ->
48+
[ assert $ foldMap_ fst_ xs ==. 100
49+
, forAll' xs $ \x y -> [20 <. x, x <. 30, y <. 100]
50+
]
51+
52+
benchSpec :: (HasSpec a, NFData a) => Int -> Int -> String -> Specification a -> Benchmark
53+
benchSpec seed size nm spec =
54+
bench (unlines [nm, show (genFromSpecWithSeed seed size spec)]) $
55+
nf (genFromSpecWithSeed seed size) spec

bench/Main.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Main where
2+
3+
import Constrained.Bench
4+
import Criterion.Main (defaultMain)
5+
6+
main :: IO ()
7+
main = defaultMain [benchmarks]

constrained-generators.cabal

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
cabal-version: 3.0
2+
name: constrained-generators
3+
version: 0.2.0.0
4+
license: Apache-2.0
5+
maintainer: [email protected]
6+
author: IOHK
7+
synopsis:
8+
Framework for generating constrained random data using
9+
a subset of first order logic
10+
11+
build-type: Simple
12+
extra-source-files: CHANGELOG.md
13+
14+
source-repository head
15+
type: git
16+
location: https://github.com/input-output-hk/constrained-generators
17+
18+
library
19+
exposed-modules:
20+
Constrained.API
21+
Constrained.API.Extend
22+
Constrained.AbstractSyntax
23+
Constrained.Base
24+
Constrained.Conformance
25+
Constrained.Core
26+
Constrained.DependencyInjection
27+
Constrained.Env
28+
Constrained.FunctionSymbol
29+
Constrained.GenT
30+
Constrained.Generation
31+
Constrained.Generic
32+
Constrained.Graph
33+
Constrained.List
34+
Constrained.NumOrd
35+
Constrained.PrettyUtils
36+
Constrained.Properties
37+
Constrained.Spec.List
38+
Constrained.Spec.Map
39+
Constrained.Spec.Set
40+
Constrained.Spec.SumProd
41+
Constrained.Spec.Tree
42+
Constrained.SumList
43+
Constrained.Syntax
44+
Constrained.Test
45+
Constrained.TheKnot
46+
Constrained.TypeErrors
47+
48+
hs-source-dirs: src
49+
default-language: Haskell2010
50+
ghc-options:
51+
-Wall
52+
-Wcompat
53+
-Wincomplete-record-updates
54+
-Wincomplete-uni-patterns
55+
-Wpartial-fields
56+
-Wredundant-constraints
57+
-Wunused-packages
58+
59+
build-depends:
60+
QuickCheck >=2.14,
61+
base >=4.18 && <5,
62+
base-orphans,
63+
containers,
64+
mtl,
65+
prettyprinter,
66+
random,
67+
template-haskell,
68+
69+
library examples
70+
exposed-modules:
71+
Constrained.Examples
72+
Constrained.Examples.Basic
73+
Constrained.Examples.BinTree
74+
Constrained.Examples.CheatSheet
75+
Constrained.Examples.Either
76+
Constrained.Examples.Fold
77+
Constrained.Examples.List
78+
Constrained.Examples.ManualExamples
79+
Constrained.Examples.Map
80+
Constrained.Examples.Set
81+
Constrained.Examples.Tree
82+
83+
hs-source-dirs: examples
84+
default-language: Haskell2010
85+
ghc-options:
86+
-Wall
87+
-Wcompat
88+
-Wincomplete-record-updates
89+
-Wincomplete-uni-patterns
90+
-Wpartial-fields
91+
-Wredundant-constraints
92+
-Wunused-packages
93+
94+
build-depends:
95+
QuickCheck >=2.14,
96+
base >=4.18 && <5,
97+
constrained-generators,
98+
containers,
99+
prettyprinter,
100+
random,
101+
102+
library testlib
103+
exposed-modules:
104+
Test.Minimal.Base
105+
Test.Minimal.Model
106+
Test.Minimal.Syntax
107+
Test.Minimal.Tuple
108+
109+
hs-source-dirs: testlib
110+
default-language: Haskell2010
111+
ghc-options:
112+
-Wall
113+
-Wcompat
114+
-Wincomplete-record-updates
115+
-Wincomplete-uni-patterns
116+
-Wpartial-fields
117+
-Wredundant-constraints
118+
-Wunused-packages
119+
120+
build-depends:
121+
QuickCheck >=2.14,
122+
base >=4.18 && <5,
123+
constrained-generators,
124+
containers,
125+
mtl,
126+
prettyprinter,
127+
128+
test-suite constrained
129+
type: exitcode-stdio-1.0
130+
main-is: Tests.hs
131+
hs-source-dirs: test
132+
other-modules: Constrained.Tests
133+
default-language: Haskell2010
134+
ghc-options:
135+
-Wall
136+
-Wcompat
137+
-Wincomplete-record-updates
138+
-Wincomplete-uni-patterns
139+
-Wpartial-fields
140+
-Wredundant-constraints
141+
-Wunused-packages
142+
-rtsopts
143+
144+
build-depends:
145+
QuickCheck,
146+
base,
147+
constrained-generators,
148+
constrained-generators:examples,
149+
containers,
150+
hspec,
151+
152+
benchmark bench
153+
type: exitcode-stdio-1.0
154+
main-is: Main.hs
155+
hs-source-dirs: bench
156+
other-modules: Constrained.Bench
157+
default-language: Haskell2010
158+
ghc-options:
159+
-Wall
160+
-rtsopts
161+
162+
build-depends:
163+
base,
164+
constrained-generators,
165+
containers,
166+
criterion,
167+
deepseq,

examples/Constrained/Examples.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Constrained.Examples (module X) where
2+
3+
import Constrained.Examples.Basic as X
4+
import Constrained.Examples.Either as X
5+
import Constrained.Examples.List as X
6+
import Constrained.Examples.Map as X
7+
import Constrained.Examples.Set as X
8+
import Constrained.Examples.Tree as X

0 commit comments

Comments
 (0)