User-defined Types
Hamler supports algebraic data types (ADTs):
-- type synonym
type Name = String
"Miles" :: Name
"Miles" :: String
newtype UInt8 = UInt8 Integer
1 :: Integer
UInt8 1 :: UInt8
-- sum datatype
data Color = Red | Green | Blue
Blue :: Color
-- product datatype
data Pair = Pair Integer Integer
Pair 3 4 :: Pair
-- record product datatype
data Person = Person {
name :: String
age :: Integer
address :: String
}
Person {name = "Miles", age = 50, address = "NY"} :: Person
-- generic datatype (maybe for example)
data Maybe a = Just a | None
data Result val err = Ok val | Error err
-- recursive datatype
data Tree = Leaf Integer | Node Tree Tree
当前内容版权归 hamler-lang 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 hamler-lang .