Logo

Programming-Idioms

History of Idiom 77 > diff from v22 to v23

Edit summary for version 23 by hrschueler:
[Haskell] Clarified on immutability
↷

Version 22

2018-05-15, 17:38:11

Version 23

2018-05-15, 17:40:17

Idiom #77 Complex number

Declare a complex x and initialize it with value (3i - 2). Then multiply it by i.

Illustration

Idiom #77 Complex number

Declare a complex x and initialize it with value (3i - 2). Then multiply it by i.

Illustration
Imports
Ă­mport Data.Complex
Imports
Ă­mport Data.Complex
Code
x = (0 :+ 1) * ((0 - 2) :+ 3)
Code
x = (0 :+ 1) * ((0 - 2) :+ 3)
Comments bubble
Declaration and initialization is not required in Haskell.
As prefix negation in Haskell is tricky, I've used (0 - 2) for (-2).
Comments bubble
Declaration and initialization is not required in Haskell.
As prefix negation in Haskell is tricky, I've used (0 - 2) for (-2).
Haskell variables are immutable, therefore "multiply it by two" is both unnecessary and too complicated.
Doc URL
http://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Complex.html
Doc URL
http://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Complex.html