Haskell: What is immutable data?

前端 未结 1 770
逝去的感伤
逝去的感伤 2020-12-21 12:12

in most articles about Haskell you\'ll find a statement like \"Data in Haskell is immutable\". I don\'t quite understand why. For example:

let a = 123
let a          


        
1条回答
  •  独厮守ぢ
    2020-12-21 12:47

    Actually, a hasn't changed. Try this in ghci to see:

    > a = 123
    > action = print a
    > a = 456
    > action
    123
    

    Compare with a language that has mutable variables, e.g. python:

    >>> a = 123
    >>> def action(): print a
    ... 
    >>> a = 456
    >>> action()
    456
    

    0 讨论(0)
提交回复
热议问题