Why am I getting "Non-exhaustive patterns in function..." when I invoke my Haskell substring function? -


I am working my way through the book. (I am the only middle path through Chapter 1, but I am still enjoying it and I intend to continue.) I have read through Section 1.5 "Playing Haskell Game", in which "many other examples Has been introduced to introduce you to [Haskell] "So far, I have learned about functions, types of announcements, protected equations, and more about inventory pattern matching, where & amp; Let's go.

I'm stuck at Exercise 1.17, which tells us to write a function object: String -> String -> Where Hair:

  1. If X Ys The prefix is ​​a substrings of xs ys
  2. If y is equal to: ys' and subdials of xs ys, there is a substrings of xs ys
  3. nothing else is Ys Substrings of

I used the prefix function given in the previous example:

  prefix :: string - & gt; String - & gt; Bull prefix [] ys = true prefix (x: x) [] = wrong prefix (x: x) (y: ys) = (x == y) & amp; Amp; Prefix xs ys  

and then tried:

  substring :: string - & gt; String - & gt; Bull subsstring x [] = incorrect sub-base xs (y: ys). Prefix xs (y: ys) = true | Substring xs ys = true | Otherwise = false  

... and its other permutations may be possible.

When I run substring "abc" xxxabcyyy " I get true , but when I run the substring" abc "xxxabyyy" I get " * exception: substring.hs: (3,0) - (5,45): non-perfect pattern in function substring" I can not understand Why can not I understand that when I use "otherwise" then how can it be without precise patterns?

BTW, the book has not yet been able to cover the other. I have it I want to keep it out of now.

You have a typo Name of the function:

  subsstring xs [] = incorrect  

due to the typo it declares a new function subsstring , not substring The case of the function.

The substring function does not have any such case that [matches the second parameter] .


Comments