referential-transparency

Does Haskell have variables?

风流意气都作罢 提交于 2019-11-26 16:05:41
问题 I've frequently heard claims that Haskell doesn't have variables; in particular, this answer claims that it doesn't, and it was upvoted at least nine times and accepted. So does it have variables or not, and why? This question also appears to apply ML, F#, OCaml, Erlang, Oz, Lava, and all SSA intermediate languages. 回答1: Haskell has immutable variables (variables in the math sense) by default: foo x y = x + y * 2 By default variables are not mutable cells . Haskell also has mutable cells

Sampling sequences of random numbers in Haskell

空扰寡人 提交于 2019-11-26 13:18:35
问题 I need small lists of gaussian random numbers for a simulation and so I tried the following: import System.Random seed = 10101 gen = mkStdGen seed boxMuller mu sigma (r1,r2) = mu + sigma * sqrt (-2 * log r1) * cos (2 * pi * r2) This is just the Box-Muller algorithm - given r1, r2 uniform random numbers in the [0,1] interval it returns a gaussian random number. normals 0 g = [] normals n g = take n $ map (boxMuller 0 1) $ pairs $ randoms g where pairs (x:y:zs) = (x,y):(pairs zs) So I used this

What is referential transparency?

这一生的挚爱 提交于 2019-11-26 04:56:38
问题 What does the term referential transparency mean? I\'ve heard it described as \"it means you can replace equals with equals\" but this seems like an inadequate explanation. 回答1: The term "referential transparency" comes from analytical philosophy, the branch of philosophy that analyzes natural language constructs, statements and arguments based on the methods of logic and mathematics. In other words, it is the closest subject outside computer science to what we call programming language