list - Is there List2D in F# like Array2D -
do have use array2d in 2d operations convert them list2d? convenient function call or library define , operate 2d list?
short answer: no, there no 2d-list.
longer answer:
i think such type problematic create, because straightforward implementations of either not have o(1) complexity on equivalent of cons operation, or break structural equality.
f# lists , arrays aren't @ same thing. let's recall facts f# lists people assume 2d-version have. they:
- are immutable
- support structural comparison
- can iteratively built via prepending elements
the equivalent of f# list in 2 dimensions can thought of rectangle in lattice-like structure such this:
n: node n-n-0 0: none | | n-n-n-0 | | | n-n-n-n-n-0 | | | | | 0 0 0 0 0
where -
denotes node on left holds reference right, , |
denotes node above holds reference node below. in one-dimensional list, each node comprise full 2d-list, namely of elements in rectangle last node on bottom-right.
since lists should immutable allow iterative construction sub-lists, creating new lists adding node valid in 3 cases:
- the new element in lowermost row of nodes
- the new element in rightmost column of nodes
- the elements (and therefore 2d-lists) formed going 1 step down or right new node non-null and able combine consistent 2d-list.
and trouble comes in. how tell 2 neighbors build on same sub-lists in structurally-compared world? can go 1 step down diagonal new node via right-down , down-right paths , see whether end @ same element. fine , dandy if results different (fail because of invalid arguments) or referentially identical (the new 2d-list valid), if contents equal identities aren't? in other words: different objects may equivalent? now, we're forced run through whole thing , compare everything, or else might end building mad graph isn't two-dimensional @ all.
this requires comparing entire sub-lists, rectangle node 1 step diagonal newly inserted node bottom-rightmost node. that's not practical; building 2d-list of n elements have o(n^2) – unless there form of optimization, such keeping track of nodes , giving equivalent nodes unique identity.
at point, guess can see why didn't make f# core library.
Comments
Post a Comment