Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does haskell throw this error?

Tags:

haskell

Trying to write function that numerize items of list and returns list of tuples with numbers, ya I know I can do it with 'zip' function, but task is to write it with recursion: so I get

cannot construct an infinite type: a = [a] when generalizing type(s) for numerize'

What am I doing wrong?

numerize' :: [a] -> Int -> [(a, Int)]
numerize' [] _ = []
numerize' [x] n = [(x, n)]
numerize' [x:xs] n = (x, n) : numerize' xs (n + 1)
like image 399
overwriter Avatar asked Mar 18 '26 15:03

overwriter


1 Answers

[x:xs]

should be

(x:xs)
like image 144
Fred Foo Avatar answered Mar 21 '26 16:03

Fred Foo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!