Vili Perše
Vili Perše

Reputation: 5

OCaml appending two lists

I know it seems like a basic question but I need help appending list s2 to list s1.
I've tried using the append function but I get an error saying:

unbound value append

Here's my code:

let s1 = [1; 2; 3; 4; 5];;
let s2 = [6; 7; 8; 9; 10];;
let s3 = append s1 s2;;

I've looked all over the internet to fix this simple problem and found nothing, so please if you know how to help, do so.

Upvotes: 0

Views: 750

Answers (1)

glennsl
glennsl

Reputation: 29106

Unless you've opened the List module, which you shouldn't, you'll have to qualify it with the module:

let s3 = List.append s1 s2;;

Alternatively there's also the @ operator:

let s3 = s1 @ s2;;

Upvotes: 4

Related Questions