[Haskell-cafe] Intuitive function given type signature
Brent Yorgey
byorgey at seas.upenn.edu
Wed May 19 11:18:36 EDT 2010
On Wed, May 19, 2010 at 04:27:14AM +0000, R J wrote:
>
> What are some simple functions that would naturally have the following type signatures:
> f :: (Integer -> Integer) -> Integer
Well, this means f is given a function from Integer to Integer, and it
has to somehow return an Integer, (possibly) using the function it is
given. For example, f could just ignore its argument:
f _ = 6
Or it could apply it to a particular input value:
f g = g 0
I'll let you think of some other possibilities.
> g :: (Integer -> Integer) -> (Integer -> Integer)
g is given an Integer->Integer function and has to produce a different
one. But as someone else pointed out, you can also think of this as
g :: (Integer -> Integer) -> Integer -> Integer
That is, g is given an Integer->Integer function as well as an
Integer, and must somehow use these things to produce another Integer.
There are lots of ways to do this--I'll let you figure this one out.
-Brent
More information about the Haskell-Cafe
mailing list