Pattern matching string prefixes in Haskell

后端 未结 5 1739
耶瑟儿~
耶瑟儿~ 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:19

    myfunc ('t' : 'o' : 'a' : 's' : 't' : 'e' : 'r' : restOfString)
    

    As far as I am aware, there is no more succinct syntax than that.

    You can of course also just check whether the string starts with toaster in a guard-clause or an if inside the function body.

提交回复
热议问题