Does anybody have an actual implementation example of something like the
Db
andDbRead
phantom types (?) he used?
This is actually fairly common, but can take a perspective shift to think about it. The easiest to spot example is Task
, albeit it’s a bit magical and built-in. Json.Decoder
is another common elm example - a type signature like intField : String -> Decoder Int
tells you that given a string it will give you back an Int while in the context of decoding some JSON.
You can of course structure your own computations in this way. One technique useful for this is defunctionalization, which allows you to express your computation as data and then execute it in a separate step/context (such as serialize the computation and send it over the network).