haskell type and typeclasses

 

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值