Type checking/inference
Derek Elkins
ddarius at hotpop.com
Sun Dec 28 07:26:37 EST 2003
On Sun, 28 Dec 2003 04:58:12 +0000
"Lee Dixon" <leedixon_2 at hotmail.com> 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.
More information about the Haskell-Cafe
mailing list