Haskell - parse error on input "=" -
i have following problem:
we can cycle list fixed amount taking given number of items off front , adding them of list. write function called rotor rotor 6 "abcdefghijklmn" produces "ghijklmnabcdef". give type definition rotor. make sure returns error message if offset number less 0 or bigger or equal length of list.
and following haskell code:
rotor :: (ord a) => -> [a] -> [a] rotor (x:xs) | if < 1 = error "error" | [] = [] | otherwise = rotor a-1 xs ++ [x]
but when compile following error:
parse error on input "="
i don't understand i'm doing wrong. ideas?
rotor :: (ord a) => -> [a] -> [a] rotor (x:xs)
this line matches non-empty lists x:xs
, only.
| if < 1 = error "error"
no if
needed here.
| [] = []
this should have been pattern: after |
boolean expression expected.
an amended version of code:
rotor :: (ord a) => -> [a] -> [a] rotor _ | < 1 = error "error" rotor _ [] = [] rotor (x:xs) = rotor a-1 xs ++ [x]
this not correct solution, yet, since not satisfy requirements, it's step in right direction.
Comments
Post a Comment