Pattern matching string prefixes in Haskell

后端 未结 5 1746
耶瑟儿~
耶瑟儿~ 2020-12-17 08:56

Let\'s say I want to make a special case for a function that matches strings that start with the character \'Z\'. I could easily do it using pattern matching by doing someth

5条回答
  •  醉话见心
    2020-12-17 09:12

    myFunc str =
      case stripPrefix "toaster" str of
         Just restOfString -> something restOfString
         Nothing -> somethingElse
    

    This is why stripPrefix returns a Maybe type.

提交回复
热议问题