I'd like to define a type that represents a unit vector.
This is what I have currently:
type UVec = UVec Float Float
unit : Float -> Float -> UVec
unit a b =
let
norm = sqrt (a^2 + b^2)
in
UVec (a/norm) (b/norm)
While unit
yields what I want, I have no way of ensuring that UVec
is always a unit vector in other parts of the program. For example, I could write something like this:
wrong = UVec 100 200
and it would compile just fine.
Is there any way to make the unit
function the sole constructor of the UVec
type? Or some way to restrict values of UVec
?