You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This general type allows the function passed to `constrained` to be any function, that given a Term, returns anytype that acts like a `Pred`.
550
550
The class IsPred is defined as follows, and has 4 instances.
551
551
552
-
```
552
+
```haskell
553
553
classShowp=>IsPredpwhere
554
554
toPred::p->Pred
555
555
@@ -615,7 +615,7 @@ type FunTy (MapList Term (ProductAsList a)) p = t1 -> t2 -> ... -> tn -> p
615
615
616
616
`assert` lifts a `(Term Bool)` to a `Pred`. by using the `IsPred` class, we can often get around using it, but it becomes necessary when we want to use the `And` operator, and the operands of `And` are a mix of `Pred`, `(Term Bool), and other operations. Here is a very simple use. Further examples illustrate its use in more challenging contexts.
617
617
618
-
```
618
+
```haskell
619
619
ex5 :: Specification [Int]
620
620
ex5 = constrained $ \ xs -> assert $ elem_ 7 xs
621
621
```
@@ -628,7 +628,7 @@ Note that `elem_` is the function symbol corresponding to `Data.List.elem`.
628
628
The library function `forAll` is used to impose a constraint on every element of a container type. There are
629
629
three `Forallable` instances in the Base system.
630
630
631
-
```
631
+
```haskell
632
632
classForallablete|t->ewhere
633
633
instanceOrdk=>Forallable (Mapkv) (k, v)
634
634
instanceOrda=>Forallable (Seta) a
@@ -637,7 +637,7 @@ instance Forallable [a] a
637
637
638
638
Here is an example of its use.
639
639
640
-
```
640
+
```haskell
641
641
ex6::Specification [Int]
642
642
ex6 = constrained $\ xs ->
643
643
forAll xs $\ x -> [ x <=.10, x >.1]
@@ -683,7 +683,7 @@ The first use: `(reifies b a f)`, says a term `b` can be obtained from a term `
683
683
Here is an example of its use. Internally, it works by forcing the solution of `a` before solving for `b`, applying the `f` to
684
684
the solution for `a`, and then constructing a `(Term b)` obtained from this value.
685
685
686
-
```
686
+
```haskell
687
687
ex7::Specification (Int,[Int])
688
688
ex7 = constrained $\ pair ->
689
689
match pair $\ n xs ->
@@ -707,7 +707,7 @@ True
707
707
The second operation `reify` can be defined using `reifies` by placing an existential constraint on the range of the function.
708
708
Here is an example of the use of `reify`
709
709
710
-
```
710
+
```haskell
711
711
ex8::Specification ([Int],[Int])
712
712
ex8 = constrained $\ pair ->
713
713
match pair $\ xs1 xs2 ->
@@ -737,7 +737,7 @@ True
737
737
The third operation `assertReified` can be used to place a boolean constraint on the existential.
738
738
Here is an example of its use.
739
739
740
-
```
740
+
```haskell
741
741
ex9::SpecificationInt
742
742
ex9 = constrained $\x ->
743
743
[ assert $ x <=.10
@@ -770,7 +770,7 @@ Sometimes we want to choose between several different specifications for the sam
770
770
Let's look at the first. Multiple constuctors from the same type. This uses the `caseOn` library functions and its two
771
771
helper functions `branch` (where each constructor is choosen equally) and `branchW` (where we can give weights, to determine the frequency each constructor is choosen). The type of `caseOn`
772
772
773
-
```
773
+
```haskell
774
774
caseOn
775
775
::Terma
776
776
->FunTy
@@ -785,15 +785,15 @@ unweighted using `(branch ...)`, where the `...` is a function with *m* paramete
785
785
subcomponents of that constructor).First we introduce a sumof products type `Three` and use the GHC.Generics
When we wish to constrain just a subset of the subcomponents, selectors make it possible
1023
1023
to write more concise `Specification`s.
1024
1024
1025
-
```
1025
+
```haskell
1026
1026
ex21::SpecificationDimensions
1027
1027
ex21 = constrained $\ d -> width_ d ==. lit 1
1028
1028
```
@@ -1038,7 +1038,7 @@ Term level names that were assigned to the Haskell variables. This means the err
1038
1038
understand. For example consider the over constrained specification. It is over constrained because
1039
1039
`left` cannot be simultaneously equal to `right` and `right + lit 1`
1040
1040
1041
-
```
1041
+
```haskell
1042
1042
ex22a::Specification (Int,Int)
1043
1043
ex22a = constrained $\ pair ->
1044
1044
match pair $\ left right ->
@@ -1061,14 +1061,14 @@ Note the error message is in terms of the internal Term name `v1`. Which is not
1061
1061
1062
1062
To make error messages clearer we can name Haskell lambda bound variables using `[var|left|]` instead of just `left`. In order to do this we must have the following directives in our file.
1063
1063
1064
-
```
1064
+
```haskell
1065
1065
{-# LANGUAGE QuasiQuotes #-}
1066
1066
{-# LANGUAGE ViewPatterns #-}
1067
1067
```
1068
1068
1069
1069
Here is the same example using this naming schema.
1070
1070
1071
-
```
1071
+
```haskell
1072
1072
ex22b::Specification (Int,Int)
1073
1073
ex22b = constrained $\ [var|pair|] ->
1074
1074
match pair $\ [var|left|] [var|right|] -> [ left ==. right, left ==. right + lit 1]
@@ -1099,7 +1099,7 @@ another internal number `y`, such that, `x` is equal to `y + y + 1`
1099
1099
1100
1100
Here is an example.
1101
1101
1102
-
```
1102
+
```haskell
1103
1103
ex22::SpecificationInt
1104
1104
ex22 = constrained $\ [var|oddx|] ->
1105
1105
unsafeExists
@@ -1114,7 +1114,7 @@ that tells how to compute the hidden variable from the values returned by solvin
1114
1114
The second is the normal use of a Haskell lambda expression to introduce a Term variable
1115
1115
naming the hidden variable. Here is an example.
1116
1116
1117
-
```
1117
+
```haskell
1118
1118
ex23::SpecificationInt
1119
1119
ex23 =ExplainSpec ["odd via (y+y+1)"] $
1120
1120
constrained $\ [var|oddx|] ->
@@ -1150,15 +1150,15 @@ If one has a term `x` with type `(Term Bool)` one could use the value of this te
1150
1150
define a Specification conditional on this term by using the `(caseOn x ...)` library function.
1151
1151
There are two more concise library function one can use instead.
0 commit comments