How can you effectively manually determine the type?

Hello, I'm new at haskell and I have the following question: let's say I type the following: function = foldr until Now my first question is what is the type of this function? Well let's see what the type of until and foldr is: until :: (a -> Bool) -> (a -> a) -> a -> a foldr :: (a -> b -> b) -> b -> [a] -> b So I would be thinking: we fill until in the position of (a -> b -> b) so, a correspond with (a -> Bool) and b correspond with (a -> a) and b correspond with a. Hmm a small problem, I think we can divide that as follows: b1 corresponds with (a -> a) and b2 corresponds with a. So I get: foldr until :: b1 -> [a] -> b2 foldr until :: (a -> a) -> [a -> Bool] -> a Is this a correct way of thinking or am I wrong? And another question is: can someone give me an example how this can be executed? All my code that I tried to execute resulted in errors with "foldr until". Thanks!

Does writing it like this help any? until :: (c -> Bool) -> (c -> c) -> (c -> c) foldr :: (( a ) -> ( b ) -> ( b )) -> b -> [a] -> b Anonymous Anonymous wrote:
Hello,
I'm new at haskell and I have the following question:
let's say I type the following:
function = foldr until
Now my first question is what is the type of this function? Well let's see what the type of until and foldr is:
until :: (a -> Bool) -> (a -> a) -> a -> a foldr :: (a -> b -> b) -> b -> [a] -> b
So I would be thinking: we fill until in the position of (a -> b -> b) so, a correspond with (a -> Bool) and b correspond with (a -> a) and b correspond with a. Hmm a small problem, I think we can divide that as follows: b1 corresponds with (a -> a) and b2 corresponds with a. So I get:
foldr until :: b1 -> [a] -> b2 foldr until :: (a -> a) -> [a -> Bool] -> a
Is this a correct way of thinking or am I wrong?
And another question is: can someone give me an example how this can be executed? All my code that I tried to execute resulted in errors with "foldr until".
Thanks!

Am Freitag, 27. Februar 2009 22:00 schrieb Anonymous Anonymous:
Hello,
I'm new at haskell and I have the following question:
let's say I type the following:
function = foldr until
Now my first question is what is the type of this function? Well let's see what the type of until and foldr is:
until :: (a -> Bool) -> (a -> a) -> a -> a foldr :: (a -> b -> b) -> b -> [a] -> b
So I would be thinking: we fill until in the position of (a -> b -> b) so, a correspond with (a -> Bool) and b correspond with (a -> a) and b correspond with a. Hmm a small problem, I think we can divide that as follows: b1 corresponds with (a -> a) and b2 corresponds with a. So I get:
Not quite. The type of until, written with one parenthesis which is not strictly necessary, is until :: (a -> Bool) -> (a -> a) -> (a -> a) Now unify that with the type of the first argument of foldr :: (s -> t -> t) -> t -> [s] -> t You get s = a -> Bool t = a -> a and foldr until :: t -> [s] -> t, which expands to foldr until :: (a -> a) -> [a -> Bool] -> (a -> a) And if you don't want to do the analysis yourself, Prelude> :t foldr until foldr until :: (a -> a) -> [a -> Bool] -> a -> a
foldr until :: b1 -> [a] -> b2 foldr until :: (a -> a) -> [a -> Bool] -> a
Is this a correct way of thinking or am I wrong?
And another question is: can someone give me an example how this can be executed? All my code that I tried to execute resulted in errors with "foldr until".
I can't really see a useful application of foldr until, sorry. But Prelude> foldr until (+1) [(> 10), (> 12)] 4 13 However: Prelude> foldr until (+1) [(> 10), (>8)] 4 Interrupted.
Thanks!
participants (3)
-
Anonymous Anonymous
-
Dan Weston
-
Daniel Fischer