A module that allows you to "tag" a value.
A Type that pairs a value
with a tag
.
The tag
is ignored at runtime as evidenced by the only value constructor:
Tagged : value -> Tagged tag value
tag : value -> Tagged tag value
An alias for the Tagged
value constructor.
retag : Tagged oldTag value -> Tagged newTag value
Explicitly changes the tag of a value.
Forces you to recognize that the value is being interpreted differently from before.
untag : Tagged tag value -> value
We can remove the tag when we're done making additional compile-time assertions.
map : (oldValue -> newValue) -> Tagged tag oldValue -> Tagged tag newValue
Useful for applying a function on a Tagged
value.
foo =
map String.toUpper aTaggedString
ap : Tagged tag (oldValue -> newValue) -> Tagged tag oldValue -> Tagged tag newValue
Useful for building more useful functions:
map f =
ap (Tagged f)
map2 f x =
ap (map f x)
map3 f x y =
ap (map2 f x y)
map2 : (a -> b -> c) -> Tagged tag a -> Tagged tag b -> Tagged tag c
An alternative to ap
:
foo =
map2 Array.get index arr
andMap : Tagged tag oldValue -> Tagged tag (oldValue -> newValue) -> Tagged tag newValue
Useful for composing functions together in a pipeline:
foo =
Tagged Array.set
|> andMap index
|> andMap value
|> andMap arr
bind : Tagged tag oldValue -> (oldValue -> Tagged tag newValue) -> Tagged tag newValue
Useful for restricting the tag created in a polymorphic function.
andThen : (oldValue -> Tagged tag newValue) -> Tagged tag oldValue -> Tagged tag newValue
Useful for restricting the tag created in a polymorphic function.
extend : (Tagged tag oldValue -> newValue) -> Tagged tag oldValue -> Tagged tag newValue
Useful when you have a function that throws away a tag prematurely, but you still need the tag later.