Re: Type checking/inference

2003-12-28 Thread s_mazanek
Hi,

 prelude :t map (foldr filter)
 map (foldr filter) :: [[a]] - [[a - Bool] - [a]]
 
 Two main questions:
 1/ How does hugs derive this answer?
 2/ What input can I give so that it yields a correct result? I've tried 
 giving it a list of lists but it fails...

Try:

map (flip (foldr filter) [even,odd]) [[1,2,3],[4,5,6]]

I guess this meets your expectation.

Without flipping the arguments:
Prelude map (foldr filter [1,2,3]) [[even]]
[[2]]
Prelude map (foldr filter [1,2,3]) [[even],[even,odd]]
[[2],[]]
Prelude map (foldr filter [1,2,3]) [[even],[even,odd],[odd]]


Bye,
Steffen
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Type checking/inference

2003-12-28 Thread Glynn Clements

Lee Dixon wrote:

 I've run into a small problem whilst doing some manual type checking, to see 
 if I could match the results given by hugs
 
 prelude :t foldr filter
 foldr filter :: [a] - [a - Bool] - [a]
 -- This was fine and was the same as my answer, so I tested it with
 prelude foldr filter [1,2,3,4] [even,odd]
 -- and the answer was indeed an empty list
 
 -- However I got stuck when attempting to derive the result of
 map (foldr filter)
 -- Hugs says that:
 prelude :t map (foldr filter)
 map (foldr filter) :: [[a]] - [[a - Bool] - [a]]
 
 Two main questions:
 1/ How does hugs derive this answer?

filter   :: (a - Bool) - [a] - [a]
foldr:: (a - b - b) - b - [a] - b
map  :: (a - b) - [a] - [b]

Passing filter as the argument to foldr instantiates a as (a - Bool)
and b as [a], giving:

foldr filter  :: [a] - [a - Bool] - [a]

Passing (foldr filter) as the argument to map instantiates a as [a]
and b as ([a - Bool] - [a]), giving:

map (foldr filter) :: [[a]] - [[a - Bool] - [a]]

 2/ What input can I give so that it yields a correct result? I've tried 
 giving it a list of lists but it fails...

The return value is a list of functions, and functions aren't
instances of Show, so it can't print the result.

Maybe you didn't mean (map (foldr filter))? The argument to map is
usually a function of one argument (i.e. a function whose result
*isn't* a function).

What are you ultimately trying to achieve?

-- 
Glynn Clements [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Type checking/inference

2003-12-28 Thread Derek Elkins
On Sun, 28 Dec 2003 04:58:12 +
Lee Dixon [EMAIL PROTECTED] wrote:

 Hi,
 
 I've run into a small problem whilst doing some manual type checking,
 to see if I could match the results given by hugs
 
 prelude :t foldr filter
 foldr filter :: [a] - [a - Bool] - [a]
 -- This was fine and was the same as my answer, so I tested it with
 prelude foldr filter [1,2,3,4] [even,odd]
 -- and the answer was indeed an empty list
 
 -- However I got stuck when attempting to derive the result of
 map (foldr filter)
 -- Hugs says that:
 prelude :t map (foldr filter)
 map (foldr filter) :: [[a]] - [[a - Bool] - [a]]
 
 Two main questions:
 1/ How does hugs derive this answer?

map :: (a - b) - [a] - [b]

foldr filter :: a' - b'
where a' = [a] and b' = [a - Bool] - [a]

map (foldr filter) :: [a'] - [b'] 
where a' = [a] and b' = [a - Bool] - [a]
so
map (foldr filter) :: [[a]] - [[a - Bool] - [a]]

 2/ What input can I give so that it yields a correct result? 

Typewise, it is the correct result for what you've provided. 
Typewise or termwise, what do you want the result to be?

 I've tried giving it a list of lists but it fails...

What does 'fails' mean? Type error, run-time error, wrong output ... ? 
What is the input? What is the expected output? What is the text of the
output (error message, actual output, etc.)?

Right now, all people can do is take guesses at what you want.

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe