1
I started messing with Haskell because of some college activity, and I’m having doubts about what the error in my code might be. The program will have two functions. 'tam', which will return the size of a string and statistics
, who receives a String
and returns a tuple of the type (String, Int)
:
- The return string will be composed of the first and last letter of the input string separated by a dot, and:
- The integer matches the size of the input string.
Input example:
statistics "carro"
-- Saída
("c.o", 5)
Or:
statistics "mala"
-- Saída:
("m.a", 4)
The code:
tam :: [a] -> Int
tam [] = 0
tam ( x:xs ) = 1 + tam xs
tupla :: (Integer, [Char])
statistics :: [Char] -> ([Char], Integer)
statistics string = print $ tupla
type tupla :: ([Char], Integer)
where tupla = ( let a = head string; b = '.'; c = last string in a+b+c,
tam string)
I got this mistake:
parse error on input `type'
I’ve tried it another way:
tam :: [a] -> Int
tam [] = 0
tam ( x:xs ) = 1 + tam xs
statistics :: [Char] -> ([Char], Integer)
statistics string = print $ tupla
where tupla = (x, y)
where x = (head string + "." + last string)
where y = (tam string)
I’m getting this mistake:
parse error on input `where'
What is not working? Vale [Edit] your reply to add more details about the error. :)
– Luiz Felipe