Failed to match the expected type `Maybe (String, Int, String) 'with the actual type` ([Char], t0, [Char])'

I am testing examples in the Haskell Tutorial for C programmers (part 2) , and I have some problems with this ...

showPet :: Maybe (String, Int, String) -> String
showPet Nothing     = "none"
showPet (Just (name, age, species)) = "a " ++ species ++ " named " ++ name ++ ", aged " ++ (show age)

While it compiles, calling it with

showPet ("cat",5,"felix")

leads to

<interactive>:131:9:
Couldn't match expected type `Maybe (String, Int, String)'
            with actual type `([Char], t0, [Char])'
In the first argument of `showPet', namely `("cat", 5, "felix")'
In the expression: showPet ("cat", 5, "felix")
In an equation for `it': it = showPet ("cat", 5, "felix")

Am I calling this incorrectly or is this a change in Haskell that makes it necessary for the change (I found several)?

+4
source share
2 answers

You indicated in the type showPetthat your first parameter should be of type showPet :: Maybe (String, Int, String), but you provided only(String, Int, String)

"" Maybe, . maybes , , , Just (Just type is a -> Maybe a)

showPet (Just ("cat",5,"felix"))

+8

, showPet Maybe something, something.

Haskell Maybe - , , . Nothing , Just.

, showPet showPet (Just ("cat",5,"felix")).

, , showPet, - showPet (Just ....

+8

Source: https://habr.com/ru/post/1548215/


All Articles