Only the ones with access to the tag constructor.
Anyone who wanted.
Create a new tagged value.
Checked with isCheckedTaggedTaggedHidden when annotated / used as an argumentEvery possible value can be described with this tag.
Tagged MetersTag FloatMetersTagged NaturalNumberTag IntInt can be called a NaturalNumberChecked instead!Anyone can access its value.
Instances can be created & updated everywhere.
Instances that are validated from inside the module where the tag is.
Anyone can read the valid value, but once you modify it, it just becomes a Tagged.
After calling tag or modifying a checked value, you get a Tagged. To tell the type that the result value is Checked, use isChecked tag.
The type of tag might even change in that operation.
oddPlusOdd : Odd -> Odd -> Even
oddPlusOdd oddToAdd =
Typed.map2 (+) oddToAdd
>> isChecked EvenRead the value inside a Tagged or Checked.
Use the values of 2 Accessibles to return a result.
type alias PrimeNumber =
Checked PrimeNumberTag Int
prime3 : PrimeNumber
prime3 =
tag 3 |> isChecked PrimeNumber
prime5 =
tag 5 |> isChecked PrimeNumberAnywhere
Typed.values2 (+) prime3 prime5
--> 8
Typed.values2 Tuple.pair prime3 prime5
--> ( 3, 5 )Using its value isn't allowed.
type alias Password =
TaggedHidden PasswordTag String
type PasswordTag
= Password Never
type alias User =
{ password : Password
--...
}
showUsYourPassword user =
-- compile-time error
user.password |> Typed.valueThe only thing you can still use is == on 2 TaggedHiddens of the same type.
A Checked value, but not everything about the value is exposed. This allows
Alter the value inside.
If the Typed was a Checked, it becomes a Typed.
type alias Meters =
Typed MetersTag Int Typed
type alias Millimeters =
Typed MilliMetersTag Typed
go1km : Meters -> Meters
go1km =
Typed.map ((+) 1000)Use the values of 2 Typeds to return a result.
The result becomes a CreatableAndModifiable with the same reading permission as the 2 inputs.
type alias PrimeNumber =
Typed PrimeNumberTag Int Checked
prime3 : PrimeNumber
prime3 =
tag 3 |> isChecked PrimeNumber
prime5 =
tag 5 |> isChecked PrimeNumberAnywhere
Typed.values2 (+) prime3 prime5
--> 8In another module
type alias NonPrime =
Checked NonPrimeTag Int
fromMultiplyingPrimes aPrime bPrime =
Typed.map2 (*) aPrime bPrime
|> isChecked NonPrime
A value is wrapped in a
typewith a phantomtag, so that aTyped A Int ...is not aTyped B Int ....The wrappers of type
TypedCheckedTaggedTaggedHiddenCheckedHiddenall promise additional type-safety.
You will see
Typedas a function argument type.Is saying:
mapworks on everyTyped. The result has the same onewhoCreatedit.Meaning if the input was
CheckedorTagged, the result becomes aTaggedCheckedHiddenorTaggedHidden, the result becomes aTaggedHidden