Stack question and list for F #

- same stack with list in F #? how about stack and sequence in f #? and what about the lineup?

+4
source share
3 answers

A sequence in F # is a lazily evaluated chain of objects similar to IEnumerable

Here is a book to read. And one more .

Citation: The Stack <T> class can be thought of as a modified version of the F # list.

+3
source

Stacks and queues are abstract data types that can be implemented in several different ways. The F # list is implemented as an immutable, simply-linked list. Since adding or removing an item from the front of a simply linked list is a constant time operation, F # lists give a good view of the stack. But adding linear time to the list, so they are less suitable for queues.

If you need an ephemeral stack, you can use the built-in System.Collections.Generic.Stack<T> . For a permanent stack, you can implement it yourself. This interface may be a good start:

 type IStack<'A> = abstract member Push : 'A -> IStack<'A> abstract member Pop : unit -> 'A * IStack<'A> 

or as a recursive data type:

 type Stack<'A> = Stack of 'A * Stack<'A> | Empty 

But in order to try to answer your question, although the stacks and lists of F # do not match, the lists are distributed in functional programming and, due to their performance characteristics, they are used in places where the C # programmer naturally reaches the stack, since they are constant, they are also better suited for functional programs (which convert fixed data structures rather than changing mutable ones).

+5
source

If you mean the stacks and queues that are learned in a typical course of data structures, then the list F # and their completely different.

0
source

All Articles