Hi!
So this is my first encounter with functional languages, and I have some hard time to get the idea. I have a basic question to " Write a function that repeats a given element the prescribed number of times and returns the result as a list". So this is my concept, but I have a feeling that this is pure rubbish:
and yup, it doesn't work. I think that second line ,where I try to create a list, is a bad idea. I also tried to treat x and y as (x,y), but it did't help.
I understand that it should do something like this 'a * int -> 'a list , but I have to create and change a list inside a function, and I don't know how to think about it.
So this is my first encounter with functional languages, and I have some hard time to get the idea. I have a basic question to " Write a function that repeats a given element the prescribed number of times and returns the result as a list". So this is my concept, but I have a feeling that this is pure rubbish:
let rec duplicate x y = let l1 in if y=0 then l1 else x::l1 duplicate x y-1;;
and yup, it doesn't work. I think that second line ,where I try to create a list, is a bad idea. I also tried to treat x and y as (x,y), but it did't help.
I understand that it should do something like this 'a * int -> 'a list , but I have to create and change a list inside a function, and I don't know how to think about it.