Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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.  Multiline code in GHCi (Shishir Srivastava)
   2. Re:  Multiline code in GHCi (divyanshu ranjan)
   3. Re:  Multiline code in GHCi (Brandon Allbery)


----------------------------------------------------------------------

Message: 1
Date: Fri, 7 Aug 2015 16:15:11 +0100
From: Shishir Srivastava <[email protected]>
To: beginners <[email protected]>
Subject: [Haskell-beginners] Multiline code in GHCi
Message-ID:
        <CALe5RTs5_2uekv4MZuGNREPzE_Z+aUzDoMHz=12nvabxlqs...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

I am trying to run this basic multiline code in GHCi. I am not sure if this
is even possible without writing it in a file and compiling it in a
traditional way.

-------
Prelude> :set +m
Prelude> let main1 = do
Prelude|             a <- readLn
Prelude|             return a
Prelude|
Prelude>
Prelude> main1

<interactive>:75:1:
    No instance for (Show (IO b0)) arising from a use of `print'
    In the first argument of `print', namely `it'
    In a stmt of an interactive GHCi command: print it
-------

Could someone please confirm if the function can be defined and called like
this in GHCi or point to where am going wrong.

Thanks,
Shishir Srivastava
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150807/c23b059c/attachment-0001.html>

------------------------------

Message: 2
Date: Fri, 7 Aug 2015 21:19:39 +0530
From: divyanshu ranjan <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Multiline code in GHCi
Message-ID:
        <cal9hw24yuhowytucmzlhfcgupneuejpqxhoutuyd2xfjtz2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Shishir,

If you wrap multiline code in between

Prelude> :{
Prelude|      let main1 = do
Prelude|                    a <- getLine
Prelude|                    return a
Prelude| :}
Prelude> main1
hello
"hello"
It will work.


On Fri, Aug 7, 2015 at 8:45 PM, Shishir Srivastava <
[email protected]> wrote:

> Hi,
>
> I am trying to run this basic multiline code in GHCi. I am not sure if
> this is even possible without writing it in a file and compiling it in a
> traditional way.
>
> -------
> Prelude> :set +m
> Prelude> let main1 = do
> Prelude|             a <- readLn
> Prelude|             return a
> Prelude|
> Prelude>
> Prelude> main1
>
> <interactive>:75:1:
>     No instance for (Show (IO b0)) arising from a use of `print'
>     In the first argument of `print', namely `it'
>     In a stmt of an interactive GHCi command: print it
> -------
>
> Could someone please confirm if the function can be defined and called
> like this in GHCi or point to where am going wrong.
>
> Thanks,
> Shishir Srivastava
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150807/1b4d1426/attachment-0001.html>

------------------------------

Message: 3
Date: Fri, 7 Aug 2015 11:51:00 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Multiline code in GHCi
Message-ID:
        <CAKFCL4WOPw++3s_23O9259rV7Q1KAFeqd-K+K54Xa32=a7v...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Fri, Aug 7, 2015 at 11:15 AM, Shishir Srivastava <
[email protected]> wrote:

> Prelude> :set +m
> Prelude> let main1 = do
> Prelude|             a <- readLn
> Prelude|             return a
> Prelude|
> Prelude>
> Prelude> main1
>
> <interactive>:75:1:
>     No instance for (Show (IO b0)) arising from a use of `print'
>

In an actual program, it would be able to apply defaulting rules and
monomorphize `b0` to Integer. The somewhat unusual ghci environment, in
particular how it tries to figure out whether to evaluate an expression and
`print` the result or instead run an IO action --- coupled with the
monomorphism restriction being disabled in the interactive context in ghci
7.8 and later --- is working against you here. As a result, you need to
specify a result type when invoking `main1`, which is what the error
message is telling you.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150807/1be5caf8/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 86, Issue 5
****************************************

Reply via email to