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. "stage restriction" when using Data.Heap (Martin Drautzburg)
2. Re: "stage restriction" when using Data.Heap (Darren Grant)
3. Re: "stage restriction" when using Data.Heap (Twan van Laarhoven)
----------------------------------------------------------------------
Message: 1
Date: Tue, 8 Jan 2013 07:03:20 +0100
From: Martin Drautzburg <[email protected]>
Subject: [Haskell-beginners] "stage restriction" when using Data.Heap
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="us-ascii"
When I :load this into ghci
import Data.Heap
heap = empty :: MinHeap (Int,String)
insert (1,"kjh") heap
I get
GHC stage restriction: `heap'
is used in a top-level splice or annotation,
and must be imported, not defined locally
In the second argument of `insert', namely `heap'
In the expression: insert (1, "kjh") heap
But when I type in
import Data.Heap
let heap = empty :: MinHeap (Int,String)
insert (1,"kjh") heap
everything works and I get
fromList [(1,"kjh")]
Why is that so and what can I do to prevent the "stage restriction"?
--
Martin
------------------------------
Message: 2
Date: Mon, 7 Jan 2013 22:40:58 -0800
From: Darren Grant <[email protected]>
Subject: Re: [Haskell-beginners] "stage restriction" when using
Data.Heap
To: Martin Drautzburg <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
<ca+jd6sgjyhrdjmezcvzip8hovumrtquinet7qmqhxo5e1fv...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
The GHC stage restriction is an error invoked when some Template Haskell
[1] construct requires the evaluation of run-time values at compile time. I
am going out on a limb and assuming that same code probably works in GHCI
because the interpreter does not have a discrete compile-time phase.
I assume that MinHeap is templated, but exactly how I do not know. Maybe
someone who is more familiar with Data.Heap will have an answer.
[1] http://www.haskell.org/haskellwiki/Template_Haskell
On Mon, Jan 7, 2013 at 10:03 PM, Martin Drautzburg <[email protected]
> wrote:
> When I :load this into ghci
>
> import Data.Heap
>
> heap = empty :: MinHeap (Int,String)
> insert (1,"kjh") heap
>
> I get
>
> GHC stage restriction: `heap'
> is used in a top-level splice or annotation,
> and must be imported, not defined locally
> In the second argument of `insert', namely `heap'
> In the expression: insert (1, "kjh") heap
>
> But when I type in
>
> import Data.Heap
>
> let heap = empty :: MinHeap (Int,String)
> insert (1,"kjh") heap
>
> everything works and I get
>
> fromList [(1,"kjh")]
>
> Why is that so and what can I do to prevent the "stage restriction"?
> --
> Martin
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130107/c9e9ef02/attachment-0001.htm>
------------------------------
Message: 3
Date: Tue, 08 Jan 2013 11:22:40 +0100
From: Twan van Laarhoven <[email protected]>
Subject: Re: [Haskell-beginners] "stage restriction" when using
Data.Heap
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
On 08/01/13 07:03, Martin Drautzburg wrote:
> import Data.Heap
>
> heap = empty :: MinHeap (Int,String)
> insert (1,"kjh") heap
Your error is in the last line. `insert (1,"kjh") heap` is an expression, and
in
Haskell expressions can only occur inside (function) declarations. So you
should
instead write something like:
heap = empty :: MinHeap (Int,String)
heap2 = insert (1,"kjh") heap
In Ghci, expressions are evaluated and the result is printed, which is why you
are able to use it there.
Twan
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 55, Issue 7
****************************************