Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Happy generated parser fails to compile. (Marc Weber)
2. Types and the difference between GHCi interactive and a file
(Russ Abbott)
3. Re: Types and the difference between GHCi interactive and a
file (Russ Abbott)
----------------------------------------------------------------------
Message: 1
Date: Sun, 26 Sep 2010 22:23:05 +0200
From: Marc Weber <[email protected]>
Subject: Re: [Haskell-beginners] Happy generated parser fails to
compile.
To: beginners <[email protected]>
Message-ID: <1285532449-sup-6...@nixos>
Content-Type: text/plain; charset=UTF-8
Excerpts from Rohit Garg's message of Sun Sep 26 16:58:05 +0200 2010:
> a) Could this be a bug in Happy (very unlikely, IMO) it is generating
> code that has type mismatches.
If you posted the error (and maybe 20 surrounding lines of code it would
be easier to help you..
No, happy does not beep on them. happy is a stupid machine which
transforms your grammar into code transforming states.
Eg if you return "foo" instead of the parser result happy will correctly
create a .hs file which will then fail to compile.
Happy only copy pastes your code.
Marc Weber
------------------------------
Message: 2
Date: Sun, 26 Sep 2010 13:46:35 -0700
From: Russ Abbott <[email protected]>
Subject: [Haskell-beginners] Types and the difference between GHCi
interactive and a file
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
The following runs without a problem.
Prelude> let null' xs = xs == []
null' :: (Eq a) => [a] -> Bool
Prelude> let main' = do print (null' [])
main' :: IO ()
Prelude> main'
True
it :: ()
But if I put essentially the same code in a file and try to load the file I
get an error.
File: Null
null' xs = xs == []
main = do print (null' [])
Prelude> :load "Null.hs"
[1 of 1] Compiling Main ( Null.hs, interpreted )
Null.hs:3:17:
Ambiguous type variable `a' in the constraint:
`Eq a' arising from a use of `null'' at Null.hs:3:17-24
Probable fix: add a type signature that fixes these type variable(s)
Failed, modules loaded: none.
Why is that?
I had thought that the ambiguity was referring to the type of [] in the
print statement, i.e., that GHC can't figure out the type of []. If I
modify the print statement to be print ( null' ([] :: [Int]) ) everything
is ok.
But if that's the case, why is this not a problem at the interactive level?
Here is a related question. In the following what does it mean to say that
x is of type [a] where "a" is a type variable?
Prelude> let x = []
x :: [a]
For example,
Prelude> x == (tail [1 :: Int])
True
it :: Bool
Prelude> x == (tail [1 :: Float])
True
it :: Bool
Prelude> (tail [1 :: Int]) == (tail [1 :: Float])
<interactive>:1:28:
Couldn't match expected type `Int' against inferred type `Float'
In the expression: 1 :: Float
In the first argument of `tail', namely `[1 :: Float]'
In the second argument of `(==)', namely `(tail [1 :: Float])'
Can a value like the value of x really be of an incompletely specified type?
I couldn't do that in the file.
When I tried the following in the file,
print (null' ([] :: (Eq a) => a))
I got this error message on loading the file.
Null.hs:3:24:
Couldn't match expected type `a1' against inferred type `[a]'
`a1' is a rigid type variable bound by
an expression type signature at Null.hs:3:34
In the first argument of `null'', namely `([] :: (Eq a) => a)'
In the first argument of `print', namely
`(null' ([] :: (Eq a) => a))'
In the expression: print (null' ([] :: (Eq a) => a))
Thanks.
-- Russ
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100926/b6b8e7a3/attachment-0001.html
------------------------------
Message: 3
Date: Sun, 26 Sep 2010 13:52:40 -0700
From: Russ Abbott <[email protected]>
Subject: [Haskell-beginners] Re: Types and the difference between GHCi
interactive and a file
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Correction. The last example should have been as follows.
When I tried the following in the file,
print (null' ([] :: (Eq a) => [a]))
I got this error message on loading the file.
Null.hs:3:24:
Ambiguous type variable `a' in the constraint:
`Eq a' arising from an expression type signature at Null.hs:3:24-42
Probable fix: add a type signature that fixes these type variable(s)
-- Russ
On Sun, Sep 26, 2010 at 1:46 PM, Russ Abbott <[email protected]> wrote:
> The following runs without a problem.
>
> Prelude> let null' xs = xs == []
> null' :: (Eq a) => [a] -> Bool
>
> Prelude> let main' = do print (null' [])
> main' :: IO ()
>
> Prelude> main'
> True
> it :: ()
>
> But if I put essentially the same code in a file and try to load the file I
> get an error.
>
> File: Null
>
> null' xs = xs == []
>
> main = do print (null' [])
>
>
> Prelude> :load "Null.hs"
> [1 of 1] Compiling Main ( Null.hs, interpreted )
>
> Null.hs:3:17:
> Ambiguous type variable `a' in the constraint:
> `Eq a' arising from a use of `null'' at Null.hs:3:17-24
> Probable fix: add a type signature that fixes these type variable(s)
> Failed, modules loaded: none.
>
> Why is that?
>
>
> I had thought that the ambiguity was referring to the type of [] in the
> print statement, i.e., that GHC can't figure out the type of []. If I
> modify the print statement to be print ( null' ([] :: [Int]) ) everything
> is ok.
>
> But if that's the case, why is this not a problem at the interactive level?
>
> Here is a related question. In the following what does it mean to say that
> x is of type [a] where "a" is a type variable?
>
> Prelude> let x = []
> x :: [a]
>
> For example,
>
> Prelude> x == (tail [1 :: Int])
> True
> it :: Bool
>
> Prelude> x == (tail [1 :: Float])
> True
> it :: Bool
>
> Prelude> (tail [1 :: Int]) == (tail [1 :: Float])
>
> <interactive>:1:28:
> Couldn't match expected type `Int' against inferred type `Float'
> In the expression: 1 :: Float
> In the first argument of `tail', namely `[1 :: Float]'
> In the second argument of `(==)', namely `(tail [1 :: Float])'
>
> Can a value like the value of x really be of an incompletely specified
> type?
>
> I couldn't do that in the file.
>
> When I tried the following in the file,
>
> print (null' ([] :: (Eq a) => a))
>
> I got this error message on loading the file.
>
> Null.hs:3:24:
> Couldn't match expected type `a1' against inferred type `[a]'
> `a1' is a rigid type variable bound by
> an expression type signature at Null.hs:3:34
> In the first argument of `null'', namely `([] :: (Eq a) => a)'
> In the first argument of `print', namely
> `(null' ([] :: (Eq a) => a))'
> In the expression: print (null' ([] :: (Eq a) => a))
>
>
> Thanks.
>
> -- Russ
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100926/70d8469b/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 27, Issue 55
*****************************************