>>> input (list natural) "[1, 2, 3]" [1,2,3]
ListLit (Just t ) [] ~ [] : t ListLit Nothing [x, y, z] ~ [x, y, z]Invariant: A non-empty list literal is always represented as ListLit Nothing xs. When an annotated, non-empty list literal is parsed, it is represented as
Annot (ListLit Nothing [x, y, z]) t ~ [x, y, z] : t
toList empty = [] toList (insert k v ctx) = (k, v) : toList ctx
>>> fromList [("B",1),("A",2)] -- The map preserves order fromList [("B",1),("A",2)] >>> fromList [("A",1),("A",2)] -- For duplicates, later values take precedence fromList [("A",2)]Note that this handling of duplicates means that fromList is not a monoid homomorphism:
>>> fromList [(1, True)] <> fromList [(1, False)] fromList [(1,True)] >>> fromList ([(1, True)] <> [(1, False)]) fromList [(1,False)]
>>> fromListWithKey (\k v1 v2 -> k ++ v1 ++ v2) [("B","v1"),("A","v2"),("B","v3")] fromList [("B","Bv3v1"),("A","v2")]
>>> toList (fromList [("B",1),("A",2)]) [("B",1),("A",2)]
>>> unorderedFromList [] fromList [] >>> unorderedFromList [("B",1),("A",2)] -- The map /doesn't/ preserve order fromList [("A",2),("B",1)] >>> unorderedFromList [("A",1),("A",2)] -- For duplicates, later values take precedence fromList [("A",2)]
>>> input (hashSetFromDistinctList natural) "[1, 2, 3]" fromList [1,2,3]An error is thrown if the list contains duplicates.
>>> input (hashSetFromDistinctList natural) "[1, 1, 3]" *** Exception: Error: Failed extraction The expression type-checked successfully but the transformation to the target type failed with the following error: One duplicate element in the list: 1
>>> input (hashSetFromDistinctList natural) "[1, 1, 3, 3]" *** Exception: Error: Failed extraction The expression type-checked successfully but the transformation to the target type failed with the following error: 2 duplicates were found in the list, including 1
>>> input (setFromDistinctList natural) "[1, 2, 3]" fromList [1,2,3]An error is thrown if the list contains duplicates.
>>> input (setFromDistinctList natural) "[1, 1, 3]" *** Exception: Error: Failed extraction The expression type-checked successfully but the transformation to the target type failed with the following error: One duplicate element in the list: 1
>>> input (setFromDistinctList natural) "[1, 1, 3, 3]" *** Exception: Error: Failed extraction The expression type-checked successfully but the transformation to the target type failed with the following error: 2 duplicates were found in the list, including 1