Does it help the compiler to optimise, or is it just surplus work to add additional type signatures? For example, one often sees:
foo :: a -> b foo x = bar x where bar x = undefined
Rather than:
foo :: a -> b foo x = bar x where bar :: a -> b bar x = undefined
If I omit the top level type signature, GHC gives me a warning, so if I don't get warnings I am quite confident my program is correct. But no warnings are issued if I omit the signature in a where clause.
There exists a class of local functions whose types cannot be written in Haskell (without using fancy GHC extensions, that is). For example:
f :: a -> (a, Int) f h = g 1 where g n = (h, n)
This is because while the a
in the f
type signature is polymorphic viewed from outside f
, this is not so from within f
. In g
, it is just some unknown type, but not any type, and (standard) Haskell cannot express "the same type as the first argument of the function this one is defined in" in its type language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With