Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@isovector
Created May 6, 2020 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isovector/f78c968f6799e17434e02686f7826df8 to your computer and use it in GitHub Desktop.
Save isovector/f78c968f6799e17434e02686f7826df8 to your computer and use it in GitHub Desktop.
-- 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