I'm a newbie regarding Haskell (and Java for that matter) and I tried to find a solution to my probably very simple problem. I need to create two arrays where it checks if the first array is a prefix of the second one, for example [5,6,7] [5,6,7,6,2] would give me the boolean true. This is what I tried, however I have no idea how to declare an array. n should be the highest slot number of array a and it counts down. As soon as one slot of a doesn't equal b it should return False. Is there another way to implement it without the n variable?
isaprefix :: [Int] -> [Int] -> Int -> Bool
isaprefix a b n = if n==0
then True
else
if a[n] == b [n]
then isaprefix ((a[n-1]) (b[n-1]))
else False
isaprefix (a !! (n - 1)) (b !! (n - 1))as the syntaxa[n-1]does not have any meaning in Haskell. (More accurately it is a function being applied to a one-element list of some element of theNumtypeclass.)prefixon Hoogle you'll find this and a click on source code reveals the same implementation ;)isaprefix a b (n-1)and then you call it withisaprefix a b (length a - 1)or something. But then ifn == 0, you should returna !! 0 == b !! 0instead of True.