Haskell REPL doesn't accept type declaration

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Haskell REPL doesn't accept type declaration

Lawrence Bottorff-2
If I simply put a type declaration into the GHCi (version 8.8.4), it complains:

Prelude> divides :: Integer -> Integer -> Bool
<interactive>:18:1-7: error:
    Variable not in scope: divides :: Integer -> Integer -> Bool

I'm trying to use Emacs org-mode babel, and I have to wrap the code block to get it to work. For example:

#+begin_src haskell :results verbatim :exports both
:{
factorial :: Int -> Int
factorial 0 = 1
factorial n = n * factorial (n - 1)
:}
#+end_src

#+begin_src haskell :results verbatim :exports both
factorial 0
#+end_src

#+RESULTS:
: 1

I understand :set +m, but this doesn't help. Why won't a running Haskell REPL with set +m take a type declaration?

Lawrence Bottorff
Grand Marais, MN, USA




_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Haskell REPL doesn't accept type declaration

Francesco Ariis
Il 10 dicembre 2020 alle 14:53 Lawrence Bottorff ha scritto:
> If I simply put a type declaration into the GHCi (version 8.8.4), it
> complains:
>
> Prelude> divides :: Integer -> Integer -> Bool
> <interactive>:18:1-7: error:
>     Variable not in scope: divides :: Integer -> Integer -> Bool
>
> I'm trying to use Emacs org-mode babel, and I have to wrap the code block
> to get it to work.

I do not believe it solves your problem but

    λ> prova :: Int; prova = 8
    λ>

works
—F
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Haskell REPL doesn't accept type declaration

Lawrence Bottorff-2
Yes, but a simple

λ> prova :: Int

doesn't work. What am I missing?


On Thu, Dec 10, 2020 at 3:11 PM Francesco Ariis <[hidden email]> wrote:
Il 10 dicembre 2020 alle 14:53 Lawrence Bottorff ha scritto:
> If I simply put a type declaration into the GHCi (version 8.8.4), it
> complains:
>
> Prelude> divides :: Integer -> Integer -> Bool
> <interactive>:18:1-7: error:
>     Variable not in scope: divides :: Integer -> Integer -> Bool
>
> I'm trying to use Emacs org-mode babel, and I have to wrap the code block
> to get it to work.

I do not believe it solves your problem but

    λ> prova :: Int; prova = 8
    λ>

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

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Haskell REPL doesn't accept type declaration

Francesco Ariis
Il 10 dicembre 2020 alle 15:41 Lawrence Bottorff ha scritto:
> Yes, but a simple
>
> λ> prova :: Int
>
> doesn't work. What am I missing?

No idea the reason why ghci does not accept it, maybe because if it did
there would be a bodyless signature in scope?

Also maybe this is slightly more palatable for you:

    λ> :set +m
    λ> let prova :: Int -> String
           prova = show
    [blank line]
    λ> prova 7
    "7"


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