-
Notifications
You must be signed in to change notification settings - Fork 7
Phantom tagging
Brian Marick edited this page May 22, 2017
·
3 revisions
Problem 1
untag : Tagged tag value -> value
untag (Tagged value) = value
Problem 2
map : (oldValue -> newValue) -> Tagged tag oldValue -> Tagged tag newValue
map f (Tagged value) =
Tagged <| f value
Problem 3
map2 : (a -> b -> c) -> Tagged tag a -> Tagged tag b -> Tagged tag c
map2 f (Tagged one) (Tagged two) =
Tagged <| f one two
With three values, I thought a -> b -> c
was as descriptive as longer identifiers and easier to skim.
Problem 4
retag : Tagged oldTag value -> Tagged newTag value
retag (Tagged x) =
Tagged x
The repetition of the (Tagged x)
makes it seems you don't need the pattern matching at all. You could just do this:
retag x = x
However, that would just return the same value passed in, with its original type. But the type annotation says it should return a (potentially) different type. Elm will refuse the second definition.