Search code examples
haskellhaskell-prelude

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.


Solution

  • 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