use :t to show expression's type
common types:
Int, bounded, in 32-bit system, between -2147483648 and 2147483648
Integer, like Int, not bounded
Float
Double
Bool
Char
typeclasses: typeclass is a sort of interface hant defines some behavior, if a type is a part of a typeclass, that means that it support and implements the behavior the typeclass describes. so we can think the typeclass is kind of as java interface
common typeclasses:
Eq, if there's an Eq class constraint for a type variable in a function, it uses == or /= somewhere inside its definition. why said it uses but not have capability? because in haskell, no variable, no object, so 只有这个函数使用了== or /=,才会说这个函数类型有Eq这个class constraint
Ord: ordering, > < >=, <=
Show: presented as string
Read: opposite typeclass of Show
Enum: members are sequentially ordered types
Bounded: members have an upper and lower bound
Num: is a numeric typeclass
Integral: is also a numeric typeclass. Num includes all numbers including real numbers and integral numbers, Integral includes only integral(whole) numbers.
Floating: includes only floating poing number
本文介绍了Haskell中的基本数据类型,如Int、Integer、Float等,并详细解释了类型类的概念及其作用,包括Eq、Ord、Show等常用类型类。
3814

被折叠的 条评论
为什么被折叠?



