functional programming - Type error in explicitly typed binding (Haskell) -


i writing simple function transforms string replacing combinations of characters another. (e.g. "ab" "a") noob in haskell, , error: "type error in explicitly typed binding"

could please tell me problem? code:

transform :: string -> string transform [] = [] transform [x] = x transform (x:y:xs)         | x == "a" && y == "b" = "a" ++ (transform xs)         | x == "b" && y == "a" = "b" ++ (transform xs)         | x == "b" && y == "b" = "a" ++ (transform xs)         | x == "a" && y == "a" = "aaa" ++ (transform xs) 

thank you!

in final transform pattern, using string literals "a" , "b" when should characters.

transform :: string -> string transform [] = [] transform [x] = [x] transform (x:y:xs)         | x == 'a' && y == 'b' = "a" ++ (transform xs)         | x == 'b' && y == 'a' = "b" ++ (transform xs)         | x == 'b' && y == 'b' = "a" ++ (transform xs)         | x == 'a' && y == 'a' = "aaa" ++ (transform xs) 

also, there bug in second transform definition, needed wrap x in brackets because returning list of characters.

(you may want have final pattern match handle other input, since you'll non-exhaustive error if run against string "zzz")


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -