type Alignment =
| Horizontal
| Vertical
let getMainAttr = function
| Horizontal -> fst
| Vertical -> snd
let check alignment =
let mainAttr = getMainAttr alignment
mainAttr (2,3) |> ignore
mainAttr (2.0, 3.0) // error
val getMainAttr : _arg1:Alignment -> ('a * 'a -> 'a)
mainAttr : (int * int -> int) // because of the value restriction
it seems the only way to make it generic is to make it explicit, e.g. let mainAttr x = getMainAttr alignment x
However, thus it no longer utilize closure, so that each time mainAttr
is called alignment
has to be checked.
Is there any way to only check alignment
once as well as being generic?