[Haskell-beginners] Multiline code in GHCi

divyanshu ranjan idivyanshu.ranjan at gmail.com
Fri Aug 7 15:49:39 UTC 2015


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 <
shishir.srivastava at gmail.com> 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
> Beginners at haskell.org
> 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.html>


More information about the Beginners mailing list