tie-knot alternatives and similar packages
Based on the "Data Structures" category.
Alternatively, view tie-knot alternatives based on common mentions on social networks and blogs.
-
Agda
Agda is a dependently typed programming language / interactive theorem prover. -
vinyl
Extensible Records for Haskell. Pull requests welcome! Come visit us on #vinyl on freenode. -
repa-scalar
High performance, regular, shape polymorphic parallel arrays. -
repa-array
High performance, regular, shape polymorphic parallel arrays. -
repa-eval
High performance, regular, shape polymorphic parallel arrays. -
repa-convert
High performance, regular, shape polymorphic parallel arrays. -
parameterized-utils
A set of utilities for using indexed types including containers, equality, and comparison. -
ethereum-client-haskell
A Haskell version of an Ethereum client -
type-level-sets
Type-level sets for Haskell (with value-level counterparts and various operations) -
justified-containers
Standard containers, with keys that carry type-level proofs of their own presence. -
bytestring-trie
An efficient finite map from (byte)strings to values. -
ixset-typed
More strongly typed variant of the ixset Haskell package -
knit
Ties the knot on data structures that reference each other by unique keys -
nonempty-containers
Efficient non-empty variants of containers data types, with full API -
claferIG
Support for reasoning on Clafer models by instantiation and counter example generation. -
eliminators
Dependently typed elimination functions using singletons -
igraph
Incomplete Haskell bindings to the igraph library (which is written in C) -
selections
Haskell Package for operating with selections over an underlying functor -
map-syntax
Syntax sugar and explicit semantics for statically defined maps
Static code analysis for 29 languages.
Do you think we are missing an alternative of tie-knot or a related project?
README
tie-knot
"Ties the knot" on a given set of structures that reference each other by
keys - replaces the keys with their respective values. Takes Map k (v k)
and
converts into Map k v'
where v'
is the fixed point of v
.
This is accomplished by functions
type RefMap k v = Map k (v k)
tie :: (Ord k, F.Foldable (Base v), Unfoldable v)
=> RefMap k (Base v) -> Either (TieError k) (Map k v)
tie' :: (Ord k, Unfoldable v)
=> RefMap k (Base v) -> Map k v
The first variant performs consistency checking (this is why it needs
Foldable
), the other just fails with an error if a key is missing in the map.
Examples:
Alice, Bob and the cat
Suppose that Alice loves Bob and her cat, Bob loves Alice and the cat loves only itself. Imagine that we're reading this information from some kind of a text file, and store the intermediate data into a list. We would like to create a data structure which would contain these cyclic dependencies:
data Person = Person { name :: String, loves :: [Person] }
-- Define a variant of Person where the recursive type
-- is given as a parameter and the embedding function.
data Person' t = Person' { _name :: String, _loves :: [t] }
type instance Base Person = Person'
instance Unfoldable Person where
embed ~(Person' n ps) = Person n ps
-- The easisest way to get 'Foldable' + 'Functor' is to implement
-- 'Traversable' and then just use the default implementations.
instance T.Traversable Person' where
traverse f (Person' n ns) = Person' n <$> T.traverse f ns
instance Functor Person' where
fmap = T.fmapDefault
instance F.Foldable Person' where
foldMap = T.foldMapDefault
-- Let's create a person with cicrular dependencies:
alice :: Person
alice = fromJust . Map.lookup "Alice" .
tie' . Map.fromList . map nameValue $ lst
where
lst = [ Person' "Alice" ["Bob", "cat"]
, Person' "Bob" ["Alice"]
-- you may disagree, but the cat thinks of itself as Person
, Person' "cat" ["cat"]
]
nameValue loves = (_name loves, loves)
Circular lists
There is a well known task of converting a list into a circular structure with no beginning/end:
data DList a = DLNode (DList a) a (DList a)
mkDList :: [a] -> DList a
We can accomplish this using tie-knot by simply numbering the fields of a list and then letting the library to tie the knot:
data DList' a t = DLNode' t a t
type instance Base (DList a) = DList' a
instance Unfoldable (DList a) where
embed ~(DLNode' u x v) = DLNode u x v
instance Functor (DList' n) where
fmap = T.fmapDefault
instance T.Traversable (DList' n) where
traverse f (DLNode' u n v) = DLNode' <$> f u <*> pure n <*> f v
instance F.Foldable (DList' n) where
foldMap = T.foldMapDefault
mkDList :: [a] -> DList a
mkDList xs =fromJust . Map.lookup 0 . tie' $ dict
where
dict = Map.fromList
. map (\(i, x) -> (i, DLNode' (pre i) x (nxt i)))
. zip [0..] $ xs
n = length xs
pre i = (i + n - 1) `rem` n
nxt i = (i + 1) `rem` n
Copyright
Copyright 2012, Petr Pudlák
Contact: petr.pudlak.name.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.
*Note that all licence references and agreements mentioned in the tie-knot README section above
are relevant to that project's source code only.