Comecei a mexer com Haskell por conta de uma atividade da faculdade e estou com dúvidas quanto ao que pode ser o erro em meu código. O programa terá duas funções. 'tam', que retornará o tamanho de uma string e statistics
, que recebe uma String
e retorna uma tupla do tipo (String, Int)
:
- A string de retorno será composta pela primeira e última letra da string de entrada separadas por um ponto, e:
- O inteiro corresponde ao tamanho da string de entrada.
Exemplo de entrada:
statistics "carro"
-- Saída
("c.o", 5)
Ou:
statistics "mala"
-- Saída:
("m.a", 4)
O código:
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)
Recebi este erro:
parse error on input `type'
Já tentei de outra forma:
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)
Estou recebendo este erro:
parse error on input `where'