Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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 <martin.drautzb...@web.de>
Subject: [Haskell-beginners] "stage restriction" when using Data.Heap
To: Haskell Beginners <beginners@haskell.org>
Message-ID: <201301080703.20818.martin.drautzb...@web.de>
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 <therealklu...@gmail.com>
Subject: Re: [Haskell-beginners] "stage restriction" when using
        Data.Heap
To: Martin Drautzburg <martin.drautzb...@web.de>
Cc: Haskell Beginners <beginners@haskell.org>
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 <martin.drautzb...@web.de
> 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
> Beginners@haskell.org
> 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 <twa...@gmail.com>
Subject: Re: [Haskell-beginners] "stage restriction" when using
        Data.Heap
To: beginners@haskell.org
Message-ID: <50ebf370.4090...@gmail.com>
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
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 55, Issue 7
****************************************

Reply via email to