Haskell: Using map with a function that returns a list? -


i have encode function:

class encode   encode :: -> [bit] 

and have problems writing function encodes list of type a list of bits. want recursively encode elements of list. in understanding can use map function purpose. problem encode returns list [bit], whereas map expects bit. how can solve this? here relevant part of program.

instance encode => encode [a]     encode [] = [i, o, o, i, o, i]     encode m = ([i, o, o] ++ (map encode m) ++ [i, o, i]) 

use concatmap. concatenates results after mapping them.

instance encode => encode [a]     encode [] = [i, o, o, i, o, i]     encode m = ([i, o, o] ++ (concatmap encode m) ++ [i, o, i]) 

how have found out yourself: if search type of function want, (a -> [bit]) -> [a] -> [bit], using hoogle, concatmap first result.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -