Across programming languages, I've encountered similar composite types with different names:
People often use the term vocabulary type,
yet I've never seen a definition of what makes a type "vocabulary".
Does this term have a loose definition?
What does type theory and other programming languages have to say about vocabulary types?
Is everything above a vocabulary type? Are there more?
My understanding of vocabulary with respect to programming and vocabulary type in general is something that gives to certain objects properties with well defined meaning.
Here are some examples in Haskell:
Consider Optional
/ Maybe
type and a pure function that takes HTTP reply of a web server and extracts reply's code.
getCode :: String -> Int
Now suppose by the time we run this function we don't know if response was successful or not - code might not be present at all. How do we represent case when code is missing? We can assign some artificial value -1
or 0
or we can change whole function type to this:
getCode :: String -> Maybe Int
In addition Maybe
forms a Monad
, Functor
, Applicative
, Foldable
and a bunch of other typeclasses in Haskell. Each typeclass adds extra abilities to manipulate value in question while respecting it's presence/absence.
Product
/ Sum
type in Haskell are represented as pairs and Either a b
. Again - defining something via Product
or Sum
adds a well defined meaning Product a b
- both values must be present, Sum a b
- one value must be present and adds a bunch of laws for free.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With