0

How can i define, run this function in prelude,

let beginsWithU (c:_) = c == 'u' || c == 'U'
   beginsWithU _ = False

Line number 2, gives parse error on input ‘=’. I cannot use let again since it will override the pattern in line 1.

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

2

How can i define, run this function in prelude

You cannot define and run a function in prelude. Prelude is a standard module which comes along with the base package which is shipped with ghc.

Assuming that you want to define and run the code in ghci, this is what you have to do:

λ> let beginsWithU (c:_) = c == 'u' || c == 'U'; beginsWithU _ = False
λ> beginsWithU "UHello"
True
Sibi
  • 47,472
  • 16
  • 95
  • 163
2

I think you want to run it inside ghci. You can use multiline input for this, the commands are :{ to start it and :} to end it.

Here's the example

Prelude> :{
Prelude| let beginsWithU (c:_) = c == 'u' || c == 'U'
Prelude|     beginsWithU _ = False
Prelude| :}
Prelude> beginsWithU "umbrella"
True
Prelude> beginsWithU "mbrella"
False
Anton Guryanov
  • 12,109
  • 1
  • 15
  • 16