mikesol / purescript-typelevel-rationals

Typelevel rationals in PureScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Qualify rationals via prism-like construct

mikesol opened this issue · comments

A typical user of Prisms is to refine input, ie:

prism' identity (\i -> if i > 0 Just i else Nothing)

It would be interesting to see if we can qualify typed rationals in a similar manner. Currently, makeRational has the broadest possible qualification, so ideally this mechanism would be a prism from the output of makeRational down to a subset (ie greater than 0).

These refinements should be treated correctly downstream. So, for example, if we have a refinement that a rational has to be greater than 0 GreaterThan x Zero True but a downstream function needs the rational to be greater than 5 GreaterThan x (PRational 5 1) True, it should fail to compile because there exists a number greater than 0 that is not greater than 5.