user2879704
user2879704

Reputation:

Make and run, beginsWithU function in prelude

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.

Upvotes: 0

Views: 53

Answers (2)

Anton Guryanov
Anton Guryanov

Reputation: 12467

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

Upvotes: 2

Sibi
Sibi

Reputation: 48654

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

Upvotes: 2

Related Questions