Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Haskell-beginners] arrow type signature question

0 views
Skip to first unread message

MH

unread,
Nov 18, 2010, 10:07:56 AM11/18/10
to begi...@haskell.org
I am looking at signatures for Arrow and Composable classes and I cannot
understand some of them. Could you please explain me the following:
Let's take for example the following:

class FunAble h => FunDble h where
resultFun :: (h b -> h b') -> (h (a->b) -> h (a->b'))

class FunAble h where
secondFun :: (h b -> h b') -> (h (a,b) -> h (a,b')) -- for 'second'


in the signatures:
resultFun :: (h b -> h b') -> (h (a->b) -> h (a->b'))
secondFun :: (h b -> h b') -> (h (a,b) -> h (a,b'))

if (h b -> h b') is the input of these functions where does 'a' comes from
in the output?

Thanks,

Daniel Fischer

unread,
Nov 18, 2010, 10:56:16 AM11/18/10
to begi...@haskell.org, MH

'a' is arbitrary, so it works for all 'a'. The result of resultFun foo,
resp. secondFun foo is a function of type

h (a -> b) -> h (a -> b')

resp.

h (a,b) -> h (a,b')

where the types b and b' have been determined by foo (not necessarily
completely, if foo is id, all that has been determined is that b' = b) and
'a' is still arbitrary. The type variable 'a' is fixed or restricted when
xxxFun gets its second argument, bar in

resultFun foo bar

resp.

secondFun foo bar.

>
> Thanks,

HTH,
Daniel

_______________________________________________
Beginners mailing list
Begi...@haskell.org
http://www.haskell.org/mailman/listinfo/beginners

MH

unread,
Nov 18, 2010, 12:51:51 PM11/18/10
to Daniel Fischer, begi...@haskell.org
Oh, so this signature is really a partial application that expects another
parameter to be executed.
So

resultFun :: (h b -> h b') -> (h (a->b) -> h (a->b'))
is
foo :: h b -> h b'
bar :: h (a->b) -> h (a->b')

firstFunction = resultFun foo
result = firstFunction bar

Is this correct?

On Thu, Nov 18, 2010 at 10:52 AM, Daniel Fischer
<daniel.i...@web.de>wrote:

Daniel Fischer

unread,
Nov 18, 2010, 1:30:42 PM11/18/10
to MH, begi...@haskell.org
On Thursday 18 November 2010 18:51:32, MH wrote:
> Oh, so this signature is really a partial application that expects
> another parameter to be executed.

Depends on how you look at it.
Strictly speaking, there is no such thing as partial application. Every
function takes exactly one argument, so it's either not applied to any
argument at all yet or it's fully applied. But the result of a function
application can be another function, so it may take another argument ...

However, always talking about functions taking an argument of type a and
returning a function taking an argument of type b and returning a function
taking an argument of type c ...
is terribly cumbersome, so we speak of functions taking several arguments.

But note that the number of arguments a function takes until the final
result is no longer a function is not always fixed. For example,
id :: a -> a takes one argument, obviously, doesn't it?
But if that argument is a function, it takes one more argument, so id can
take two arguments, or three, or however many you want, it depends on which
arguments you pass.

So when you have a value of type a -> b -> c (which is the same as
a -> (b -> c), since the function arrow is right-associative), and apply it
to a value of type a, sometimes it is more appropriate to think of that as
a partial application, sometimes as a complete application resulting in a
function.

> So
> resultFun :: (h b -> h b') -> (h (a->b) -> h (a->b'))

which is

resultFun :: (h b -> h b') -> h (a -> b) -> h (a -> b')

> is
> foo :: h b -> h b'

Yes

> bar :: h (a->b) -> h (a->b')

No. bar :: h (a -> b)

resultFun foo :: h (a -> b) -> h (a -> b')

so it takes an argument of type h (a -> b) and its result has type


h (a -> b')

(which may be another function type, if h x = e -> x).

>
> firstFunction = resultFun foo
> result = firstFunction bar

Yep

>
> Is this correct?

MH

unread,
Nov 18, 2010, 1:44:00 PM11/18/10
to Daniel Fischer, begi...@haskell.org
I got it. Thanks a lot. By the way, can you provide with example of using
resultFun or secondFun.
I did search on Hyahoo and Hoogle for names and signatures and I didn't see
any.

Thanks,

Malik

Daniel Fischer

unread,
Nov 18, 2010, 2:06:57 PM11/18/10
to MH, begi...@haskell.org
On Thursday 18 November 2010 19:43:43, MH wrote:
> I got it.

Great.

> Thanks a lot.

'twas a pleasure.

> By the way, can you provide with example of using resultFun or secondFun.

No, sorry, I've never used them myself nor came across code using them.

> I did search on Hyahoo and Hoogle for names and signatures and I didn't
> see any.
>
> Thanks,
>
> Malik

_______________________________________________

0 new messages