I have a problem with the following function
sum f l1 l2 = (f l1) + (f l2)
It doesn't work with sum length [1,2] ['a','b']. When I try this I get
No instance for (Num Char) arising from the literal ‘1’
error so the problem is with types. When I try :t function, I get sum :: Num a => (t -> a) -> t -> t -> a. So, if I understand this correctly, I can't just use + function with both numerical and character values at the same time but I lack the deeper understanding of why exactly is this the case and how to fix it.
I tried a couple of things, like using let for one of the literals or id function, but this doesn't seem to work. Any help?
length :: [Int] -> Intis not the same function aslength :: [Char] -> Int. Here you thus forcefto to have a specific type, but that is not applicable to both inputsl1andl2.letfor one of the inputs so that they don't have the same type when usinglengthfunction but that doesn't work.sequence [length.fst,length.snd] ([1,2], ['a','b'])