It's tempting to want something like

type clone Name = String
type clone Currency = Int
type alias Accounts = Dict Name Currency

These hypothetical "type clones" would act like their base type until you 
tried to use them in nonsensical ways. But trying to define their behavior 
is tricky.

The Haskell community has apparently tried this under the name "subtypes" 
and concluded they are very difficult to implement and have other 
undesirable properties, but I couldn't find anything formal.

More concretely, say one defines type clones for Length and Width in the 
hope of avoiding accidentally adding them, which would make no sense. But 
we'd want to allow multiplying them to obtain Area. The only language I 
know that handles this well is Frink <https://frinklang.org/>, which tracks 
physical units through all computations.

All that said, it may be possible to define this well enough and simply 
enough to warrant further explanation. For example, in any correct program 
with type clones, one should be able to replace any clone with an alias and 
have identical code generated. If there's interest, I can start a new 
thread exploring these type clones further.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to