Skip to content

Sequences vs. Lists in F*: when to use each #3191

Answered by nikswamy
klinvill asked this question in Q&A
Discussion options

You must be logged in to vote

Sequences provide a functional-array interface to lists. The sequence interface is oriented around index-based operations---Seq.index, Seq.slice etc. Lists, in contrast, are more idiomatically used with pattern matching and induction or recursion.

I would use seq when the common operations on a structure are index-based, e.g., we use seq in libraries like LowStar.Buffer, Pulse.Lib.Array etc., as a functional model of mutable arrays.

Use list when the common operations are maps and folds.

The are conversions in both directions: seq_to_list and seq_of_list. So, if you do start off using lists and find that in a part of your development, sequences would be better, or vice versa, then you can…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by klinvill
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants