packages feed

hydra-kernel-0.18.1: hydra-kernel-json/hydra/core/lib/sets.json

{
  "name": "hydra.core.lib.sets",
  "metadata": {
    "description": "Primitives in the hydra.core.lib.sets module.",
    "comments": [
      "Ordered sets: finite collections of distinct elements.",
      "Hydra sets are ordered collections: iteration (toList) is in ascending element order, under the type's total order.",
      "Because element ordering is part of the set type's contract, every set-typed variable in this module's signatures carries the ordering constraint on its element type, including in primitives that perform no comparison themselves."],
    "seeAlso": [],
    "provisions": []},
  "dependencies": [
    {"module": "hydra.core.lib.lists"},
    {"module": "hydra.core.lib.logic"},
    {"module": "hydra.core.model"},
    {"module": "hydra.core.packaging"},
    {"module": "hydra.core.typing"}],
  "definitions": [
    {
      "primitive": {
        "name": "hydra.core.lib.sets.delete",
        "metadata": {
          "description": "Remove an element from a set.",
          "comments": [
            "delete(x, s) returns s with x removed; if x is not in s, s is returned unchanged.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.delete :: Ord a => a -> Set a -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.delete.removesElement",
              "kind": "requirement",
              "statement": "delete removes the given element from the set if present, leaving every other element unchanged."},
            {
              "name": "hydra.core.lib.sets.delete.noOpWhenAbsentOrEmpty",
              "kind": "requirement",
              "statement": "delete returns the set unchanged when the element is not present, including when the set is empty."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {"name": "x", "description": "the element to remove", "type": {"variable": "x"}, "isLazy": false},
            {"name": "s", "description": "the set to remove the element from", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.difference",
        "metadata": {
          "description": "Compute the difference of two sets: elements in the first that are not in the second.",
          "comments": [
            "difference(s1, s2) returns the set of elements that are in s1 but not in s2.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.difference :: Ord a => Set a -> Set a -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.difference.removesElementsOfSecondSet",
              "kind": "requirement",
              "statement": "difference returns the elements of the first set that do not occur in the second set."},
            {
              "name": "hydra.core.lib.sets.difference.identityWhenSecondEmpty",
              "kind": "requirement",
              "statement": "difference with an empty second set returns the first set unchanged."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {"name": "s1", "description": "the set to subtract from", "type": {"set": {"variable": "x"}}, "isLazy": false},
            {"name": "s2", "description": "the set of elements to remove", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true,
        "defaultImplementation": {
          "lambda": {
            "parameter": "s1",
            "body": {
              "lambda": {
                "parameter": "s2",
                "body": {
                  "application": {
                    "function": {
                      "application": {
                        "function": {
                          "application": {
                            "function": {"variable": "hydra.core.lib.lists.foldl"},
                            "argument": {
                              "lambda": {
                                "parameter": "acc",
                                "body": {
                                  "lambda": {
                                    "parameter": "el",
                                    "body": {
                                      "application": {
                                        "function": {
                                          "application": {
                                            "function": {
                                              "application": {
                                                "function": {"variable": "hydra.core.lib.logic.ifElse"},
                                                "argument": {
                                                  "application": {
                                                    "function": {"application": {"function": {"variable": "hydra.core.lib.sets.member"}, "argument": {"variable": "el"}}},
                                                    "argument": {"variable": "s2"}}}}},
                                            "argument": {"variable": "acc"}}},
                                        "argument": {
                                          "application": {
                                            "function": {"application": {"function": {"variable": "hydra.core.lib.sets.insert"}, "argument": {"variable": "el"}}},
                                            "argument": {"variable": "acc"}}}}}}}}}}},
                        "argument": {"variable": "hydra.core.lib.sets.empty"}}},
                    "argument": {"application": {"function": {"variable": "hydra.core.lib.sets.toList"}, "argument": {"variable": "s1"}}}}}}}}}}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.empty",
        "metadata": {
          "description": "The empty set.",
          "comments": [
            "empty is the set with no elements.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.empty :: Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.empty.hasNoElements",
              "kind": "requirement",
              "statement": "empty is the set containing no elements, for any element type."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.filter",
        "metadata": {
          "description": "Filter a set by a predicate.",
          "comments": [
            "filter(p, s) returns the subset of s containing exactly the elements x for which p(x) is true.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.filter :: (a -> Bool) -> Set a -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.17.6"},
          "provisions": []},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {
              "name": "predicate",
              "description": "the predicate to test each element",
              "type": {"function": {"domain": {"variable": "x"}, "codomain": {"literal": "boolean"}}},
              "isLazy": false},
            {"name": "s", "description": "the set to filter", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true,
        "defaultImplementation": {
          "lambda": {
            "parameter": "p",
            "body": {
              "lambda": {
                "parameter": "s",
                "body": {
                  "application": {
                    "function": {"variable": "hydra.core.lib.sets.fromList"},
                    "argument": {
                      "application": {
                        "function": {"application": {"function": {"variable": "hydra.core.lib.lists.filter"}, "argument": {"variable": "p"}}},
                        "argument": {"application": {"function": {"variable": "hydra.core.lib.sets.toList"}, "argument": {"variable": "s"}}}}}}}}}}}}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.fromList",
        "metadata": {
          "description": "Construct a set from a list of elements (duplicates removed).",
          "comments": [
            "fromList(xs) returns the set containing exactly the distinct elements of xs; duplicates are discarded.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.fromList :: Ord a => [a] -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.fromList.collectsDistinctElements",
              "kind": "requirement",
              "statement": "fromList returns the set of the distinct elements of the given list, discarding duplicates and order."},
            {
              "name": "hydra.core.lib.sets.fromList.emptyListYieldsEmptySet",
              "kind": "requirement",
              "statement": "fromList of the empty list is the empty set."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {
              "name": "xs",
              "description": "the list of elements to build the set from",
              "type": {"list": {"variable": "x"}},
              "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.insert",
        "metadata": {
          "description": "Add an element to a set.",
          "comments": [
            "insert(x, s) returns s with x added; if x is already in s, s is returned unchanged.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.insert :: Ord a => a -> Set a -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.insert.addsElement",
              "kind": "requirement",
              "statement": "insert adds the given element to the set, leaving every other element unchanged."},
            {
              "name": "hydra.core.lib.sets.insert.noOpWhenAlreadyPresent",
              "kind": "requirement",
              "statement": "insert returns the set unchanged when the element is already present."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {"name": "x", "description": "the element to add", "type": {"variable": "x"}, "isLazy": false},
            {"name": "s", "description": "the set to add the element to", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.intersection",
        "metadata": {
          "description": "Compute the intersection of two sets: elements present in both.",
          "comments": [
            "intersection(s1, s2) returns the set of elements present in both s1 and s2.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.intersection :: Ord a => Set a -> Set a -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.intersection.keepsElementsInBoth",
              "kind": "requirement",
              "statement": "intersection returns exactly the elements present in both sets."},
            {
              "name": "hydra.core.lib.sets.intersection.emptyWhenNoOverlapOrEitherEmpty",
              "kind": "requirement",
              "statement": "intersection is the empty set when the two sets share no elements, or when either set is empty."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {"name": "s1", "description": "the first set", "type": {"set": {"variable": "x"}}, "isLazy": false},
            {"name": "s2", "description": "the second set", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true,
        "defaultImplementation": {
          "lambda": {
            "parameter": "s1",
            "body": {
              "lambda": {
                "parameter": "s2",
                "body": {
                  "application": {
                    "function": {
                      "application": {
                        "function": {
                          "application": {
                            "function": {"variable": "hydra.core.lib.lists.foldl"},
                            "argument": {
                              "lambda": {
                                "parameter": "acc",
                                "body": {
                                  "lambda": {
                                    "parameter": "el",
                                    "body": {
                                      "application": {
                                        "function": {
                                          "application": {
                                            "function": {
                                              "application": {
                                                "function": {"variable": "hydra.core.lib.logic.ifElse"},
                                                "argument": {
                                                  "application": {
                                                    "function": {"application": {"function": {"variable": "hydra.core.lib.sets.member"}, "argument": {"variable": "el"}}},
                                                    "argument": {"variable": "s2"}}}}},
                                            "argument": {
                                              "application": {
                                                "function": {"application": {"function": {"variable": "hydra.core.lib.sets.insert"}, "argument": {"variable": "el"}}},
                                                "argument": {"variable": "acc"}}}}},
                                        "argument": {"variable": "acc"}}}}}}}}},
                        "argument": {"variable": "hydra.core.lib.sets.empty"}}},
                    "argument": {"application": {"function": {"variable": "hydra.core.lib.sets.toList"}, "argument": {"variable": "s1"}}}}}}}}}}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.isEmpty",
        "metadata": {
          "description": "Test whether a set is empty.",
          "comments": [
            "isEmpty(s) returns true iff s has no elements.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.null :: Set a -> Bool."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.isEmpty.testsZeroSize",
              "kind": "requirement",
              "statement": "isEmpty returns true exactly when the set has no elements."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [{"name": "s", "description": "the set to test for emptiness", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"literal": "boolean"}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.map",
        "metadata": {
          "description": "Map a function over a set.",
          "comments": [
            "map(f, s) returns the set of f(x) for each x in s. Elements that f maps to the same image are deduplicated by the result type's ordering.",
            "Requires 'ordering' constraints on both the input and output element types.",
            "Total. Corresponds to Haskell's Data.Set.map :: (Ord a, Ord b) => (a -> b) -> Set a -> Set b."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.map.appliesFunctionToEachElement",
              "kind": "requirement",
              "statement": "map returns the set of applying the given function to each element, deduplicating results that collide under the output type's ordering."},
            {
              "name": "hydra.core.lib.sets.map.emptyInput",
              "kind": "requirement",
              "statement": "map over the empty set is the empty set, regardless of the function."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}, {"name": "y", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {
              "name": "f",
              "description": "the function to apply to each element",
              "type": {"function": {"domain": {"variable": "x"}, "codomain": {"variable": "y"}}},
              "isLazy": false},
            {"name": "s", "description": "the set to map over", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"set": {"variable": "y"}}}},
        "isPure": true,
        "isTotal": true,
        "defaultImplementation": {
          "lambda": {
            "parameter": "f",
            "body": {
              "lambda": {
                "parameter": "s",
                "body": {
                  "application": {
                    "function": {"variable": "hydra.core.lib.sets.fromList"},
                    "argument": {
                      "application": {
                        "function": {"application": {"function": {"variable": "hydra.core.lib.lists.map"}, "argument": {"variable": "f"}}},
                        "argument": {"application": {"function": {"variable": "hydra.core.lib.sets.toList"}, "argument": {"variable": "s"}}}}}}}}}}}}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.member",
        "metadata": {
          "description": "Test whether an element is in a set.",
          "comments": [
            "member(x, s) returns true iff x is an element of s.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.member :: Ord a => a -> Set a -> Bool."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.member.testsSetMembership",
              "kind": "requirement",
              "statement": "member returns true exactly when the given value is an element of the set."},
            {
              "name": "hydra.core.lib.sets.member.falseWhenAbsentOrEmpty",
              "kind": "requirement",
              "statement": "member returns false when the value is not an element of the set, including when the set is empty."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {"name": "x", "description": "the element to test for membership", "type": {"variable": "x"}, "isLazy": false},
            {"name": "s", "description": "the set to test against", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"literal": "boolean"}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.singleton",
        "metadata": {
          "description": "Construct a set containing a single element.",
          "comments": [
            "singleton(x) returns the set containing exactly the element x.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.singleton :: a -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.singleton.wrapsOneElement",
              "kind": "requirement",
              "statement": "singleton x returns the set containing exactly the element x."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [{"name": "x", "description": "the single element of the set", "type": {"variable": "x"}, "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.size",
        "metadata": {
          "description": "Return the number of elements in a set.",
          "comments": [
            "size(s) returns the number of elements in s as an int32.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.size :: Set a -> Int (with narrowing to int32)."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.size.countsElements",
              "kind": "requirement",
              "statement": "size returns the number of elements in the set, including zero for the empty set."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [{"name": "s", "description": "the set whose size is returned", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"literal": {"integer": "int32"}}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.toList",
        "metadata": {
          "description": "Convert a set to a list (in ascending order).",
          "comments": [
            "toList(s) returns the elements of s as a list, in ascending order under the element type's ordering.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.toAscList :: Set a -> [a]."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.toList.ordersAscending",
              "kind": "requirement",
              "statement": "toList returns the elements of the set as a list in ascending order under the element type's ordering, regardless of insertion order."},
            {
              "name": "hydra.core.lib.sets.toList.emptySetYieldsEmptyList",
              "kind": "requirement",
              "statement": "toList of the empty set is the empty list."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [{"name": "s", "description": "the set to convert to a list", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"list": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.union",
        "metadata": {
          "description": "Compute the union of two sets: elements in either.",
          "comments": [
            "union(s1, s2) returns the set of elements that are in s1 or in s2 (or both).",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.union :: Ord a => Set a -> Set a -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.union.keepsElementsInEither",
              "kind": "requirement",
              "statement": "union returns the elements that are in either set (or both), with no duplicates."},
            {
              "name": "hydra.core.lib.sets.union.identityWhenEitherEmpty",
              "kind": "requirement",
              "statement": "union with either set empty returns the other set unchanged."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {"name": "s1", "description": "the first set", "type": {"set": {"variable": "x"}}, "isLazy": false},
            {"name": "s2", "description": "the second set", "type": {"set": {"variable": "x"}}, "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true,
        "defaultImplementation": {
          "lambda": {
            "parameter": "s1",
            "body": {
              "lambda": {
                "parameter": "s2",
                "body": {
                  "application": {
                    "function": {
                      "application": {
                        "function": {
                          "application": {
                            "function": {"variable": "hydra.core.lib.lists.foldl"},
                            "argument": {
                              "lambda": {
                                "parameter": "acc",
                                "body": {
                                  "lambda": {
                                    "parameter": "el",
                                    "body": {
                                      "application": {
                                        "function": {"application": {"function": {"variable": "hydra.core.lib.sets.insert"}, "argument": {"variable": "el"}}},
                                        "argument": {"variable": "acc"}}}}}}}}},
                        "argument": {"variable": "s2"}}},
                    "argument": {"application": {"function": {"variable": "hydra.core.lib.sets.toList"}, "argument": {"variable": "s1"}}}}}}}}}}},
    {
      "primitive": {
        "name": "hydra.core.lib.sets.unions",
        "metadata": {
          "description": "Compute the union of a list of sets.",
          "comments": [
            "unions(ss) returns the union of every set in ss. Equivalent to folding union over ss starting from empty.",
            "Requires an 'ordering' constraint on the element type.",
            "Total. Corresponds to Haskell's Data.Set.unions :: Ord a => [Set a] -> Set a."],
          "seeAlso": [],
          "lifecycle": {"availableSince": "0.15"},
          "provisions": [
            {
              "name": "hydra.core.lib.sets.unions.keepsElementsInAny",
              "kind": "requirement",
              "statement": "unions returns the elements that occur in at least one of the given sets, equivalent to folding union over the list starting from empty."},
            {
              "name": "hydra.core.lib.sets.unions.emptyListOfSetsYieldsEmptySet",
              "kind": "requirement",
              "statement": "unions of an empty list of sets is the empty set."}]},
        "signature": {
          "typeParameters": [{"name": "x", "constraints": [{"simple": "ordering"}]}],
          "parameters": [
            {
              "name": "ss",
              "description": "the list of sets to union together",
              "type": {"list": {"set": {"variable": "x"}}},
              "isLazy": false}],
          "result": {"type": {"set": {"variable": "x"}}}},
        "isPure": true,
        "isTotal": true,
        "defaultImplementation": {
          "lambda": {
            "parameter": "ss",
            "body": {
              "application": {
                "function": {
                  "application": {
                    "function": {
                      "application": {
                        "function": {"variable": "hydra.core.lib.lists.foldl"},
                        "argument": {
                          "lambda": {
                            "parameter": "acc",
                            "body": {
                              "lambda": {
                                "parameter": "s",
                                "body": {
                                  "application": {
                                    "function": {"application": {"function": {"variable": "hydra.core.lib.sets.union"}, "argument": {"variable": "acc"}}},
                                    "argument": {"variable": "s"}}}}}}}}},
                    "argument": {"variable": "hydra.core.lib.sets.empty"}}},
                "argument": {"variable": "ss"}}}}}}}]}