2 ms·
* define a typeclass with a function generic in its output * implement the typeclass for relevant types * invoke the typeclass function in disambiguated conte
by masklinn 9y ago
* define a typeclass with a function generic in its output
* implement the typeclass for relevant types
* invoke the typeclass function in disambiguated contexts
class Zero z where
zero :: z
instance Zero Int where
zero = 0
instance Zero Float where
zero = 0.0
instance Zero [a] where
zero = []
example usage:
let v :: Int; v = zero
or
let v = zero :: Int
or pass it to something which expects an Int, disambiguating it, e.g.
> Data.Char.chr zero
'\NUL'