Created
May 6, 2020 05:39
-
-
Save isovector/f78c968f6799e17434e02686f7826df8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- I am designing an API. This is not real haskell code, but it is accepted by my tool. | |
-- I can define type sigs as usual | |
query :: Query a -> System -> [a] | |
-- I can also write laws that the eventual implementation must satisfy. | |
-- lines that begin with a string are laws. | |
-- notice that these are _not even_ haskell definitions, because the LHS is not a pattern. | |
"1" queryEntity ix (refine (const False) q) s = Nothing | |
"2" queryEntity ix (refine (const True) q) = queryEntity ix q | |
"3" queryEntity ix (mapQ f q) = fmap f . queryEntity ix q | |
-- the tool will gather these laws, and construct the following: | |
properties :: [Property] | |
properties = | |
[ (queryEntity ix (refine (const False) q) s) =-= (Nothing) | |
, (queryEntity ix (refine (const True) q)) =-= (queryEntity ix q) | |
, (queryEntity ix (mapQ f q)) =-= (fmap f . queryEntity ix q) | |
] | |
-- (=-=) :: EqProp a => a -> a -> Property | |
-- | |
-- because (=-=) consumes polymorphic inputs, and because `queryEntity` _produces_ polymorphic | |
-- outputs, these expressions are ambiguous in `a`. But it can't possibly matter, so defaulting | |
-- is a very reasonable thing to do |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment