User-defined data types Mapping
The constructors of Sum/Product algebraic data types are mapping to tuples in Erlang at compile-time.
Hamler:
-- Sum datatype
data Color = Red | Green | Blue
Red -- {'Red'}
Green -- {'Green'}
Blue -- {'Blue'}
-- Product datatype
data Pair = Pair Integer Integer
Pair 3 4 -- {'Pair',3,4}
-- Maybe
data Maybe a = Just a | Nothing
Nothing -- {'Nothing'}
Just 5 -- {'Just',5}
Erlang:
{'Red'} %% Red
{'Green'} %% Green
{'Blue'} %% Blue
{'Pair',3,4} %% Pair 3 4
{'Nothing'} %% Nothing
{'Just',5} %% Just 5
当前内容版权归 hamler-lang 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 hamler-lang .