2

Is it possible to write multi-line function definitions with type-signature inside GHCi (as you would write it in a source file)?

I've tried so far something like this:

Prelude> :{
Prelude| let f :: Int -> Int;
Prelude| f i = i + 1
Prelude| :}

<interactive>:9:1: parse error on input ‘f’

but it didn't work... Is there anything else I could try?

Cœur
  • 37,241
  • 25
  • 195
  • 267
bmk
  • 1,548
  • 9
  • 17
  • 1
    possible duplicate of [How to define a function in ghci across multiple lines?](http://stackoverflow.com/questions/2846050/how-to-define-a-function-in-ghci-across-multiple-lines) – shree.pat18 Dec 16 '14 at 09:03
  • 2
    You probably need to indent the line it's complaining about. – MathematicalOrchid Dec 16 '14 at 09:06
  • @shree.pat18 Thank you for your link to the possible duplicate question. I've actually read it before, but I couldn't find a way from the answers there how I could add the **type-signature** to the multi-line function definition inside `:{ :}`, so I've opened new question, but well since it was simple stupid identation problem from me, we could close this question. – bmk Dec 16 '14 at 09:19

1 Answers1

4

Mind the indentation:

Prelude> :{
Prelude| let f :: Int -> Int
Prelude|     f i = i + 1
Prelude| :}
Prelude> :t f
f :: Int -> Int
Prelude> f 1
2
Tomo
  • 3,431
  • 5
  • 25
  • 28