2019-05-27 弱类型、强类型、动态类型、静态类型

2019-05-27 弱类型、强类型、动态类型、静态类型_第1张图片
image

2019-05-27 弱类型、强类型、动态类型、静态类型_第2张图片
image

弱类型

> "1"+2
'12'

强类型

> "1"+2
Traceback (most recent call last):
  File "", line 1, in 
TypeError: cannot concatenate 'str' and 'int' objects

动态类型

> a = 1
> type(a)

> a = "s"
> type(a)

静态类型

Prelude> let a = "123" :: Int

:2:9:
    Couldn't match expected type `Int' with actual type `[Char]'
    In the expression: "123" :: Int
    In an equation for `a': a = "123" :: Int

你可能感兴趣的:(2019-05-27 弱类型、强类型、动态类型、静态类型)