Structs
Elchemy represents all the structs as maps, so a struct defined like
human : { name : String , age : Int }
Is an equivalent of
@spec human :: %{ name : String.t(), age : integer() }
Also type aliases denoting structs can be instatiated like functions
type alias Human = { name : String , age : Int } Human "Krzysztof" 22
What's more structs can describe a map that has at least specified elements using an update syntax.
type alias Employee x = { x | salary : Int }
Which basically means any struct that has a field salary
of type integer.
That way we can define our psuedo-inheritance and polymorphism for more advanced structures.
type alias Human = Employee { name : String , age : Int } human : Human
Would resolve to
@spec human :: %{ salary : integer(), name : String.t, age : integer()}
But be advised that using this "polymorhpic" approach strips us from the abilty to use type aliases as constructors.