As far as I know String is a type in Haskell:
type String = [Char]
Then I don’t understand why the following code:
stringDecode :: String -> Maybe String
stringDecode s =
let
splitByColon x' = splitAt x' s
in case findIndex (\b -> b == ':') s of
(Just x) -> snd (splitByColon x)
(Nothing) -> Nothing
Gives the following type error on compilation:
Couldn't match expected type `Maybe String'
with actual type `[Char]'
Expected type: ([Char], Maybe String)
Actual type: ([Char], [Char])
In the return type of a call of `splitByColon'
In the first argument of `snd', namely `(splitByColon x)'
EDIT: Fixed actually the problem was with the return expected of Maybe String whereas I returned [Char] and returning Just [Char] did work.
Because your line
(Just x) -> snd (splitByColon x)is attempting to return aStringinstead of aMaybe String. You should replace that with(Just x) -> Just $ snd (splitByColon x)