basic.hs:
areaCircle :: Floating -> Floating
areaCircle r = pi * r * r
Command:
*Main> :l basic.hs
[1 of 1] Compiling Main ( Sheet1.hs, interpreted )
Sheet1.hs:2:15:
Expecting one more argument to `Floating'
In the type signature for `areaCircle':
areaCircle :: Floating -> Floating
Failed, modules loaded: none.
I see that areaCircle :: Floating a => a -> a loads as expected. Why is the above version not acceptable?
Because your version does not actually supply a type.
Floatingis a type class. If you want to allow any Floating, thenFloating a => a -> ais correct. Otherwise you can try eitherFloat -> FloatorDouble -> Double.Just to flesh it out a bit more:
Floating a => a -> asays not only that your function accepts anyFloatingtype, but that it returns the same type it is passed. This must be true even if you narrow the type. For example, you would not be able to useFloat -> Doublewithout doing some additional conversions