referential-transparency

Are there any purely functional Schemes or Lisps?

独自空忆成欢 提交于 2019-11-29 22:55:58
I've played around with a few functional programming languages and really enjoy the s-expr syntax used by Lisps (Scheme in particular). I also see the advantages of working in a purely functional language. Therefore: Are there any purely functional Schemes (or Lisps in general)? Probably not, at least not as anything other than toys/proofs of concept. Note that even Haskell isn't 100% purely functional--it has secret escape hatches, and anything in IO is only "pure" in some torturous, hand-waving sense of the word . So, that said, do you really need a purely functional language? You can write

Zipper like data structure with more than one cursor

巧了我就是萌 提交于 2019-11-29 00:39:43
问题 The Zipper data structure is great when one wants to traverse a tree and keep the current position, but what data structure one should use if they want to track more then one position? Let me explain with examples: Someone on the #haskell channel has told me that zippers are used in yi editor to represent the cursor position. This is great, but what if you want to have two cursors. Like if you want to represent a selection, you need to know the beginning and the end of the selection. In the

How do functional languages model side-effects?

馋奶兔 提交于 2019-11-28 19:22:41
Since side-effects break referential transparency, don't they go against the point of functional languages? There are two techniques that are used by purely functional programming languages to model side effects: 1) A world type that represents external state, where each value of that type is guaranteed by the type system to be used only once. In a language that uses this approach the function print and read might have the types (string, world) -> world and world -> (string, world) respectively. They might be used like this: let main w = let w1 = print ("What's your name?", w) in let (str, w2)

Purity vs Referential transparency

那年仲夏 提交于 2019-11-28 04:37:55
The terms do appear to be defined differently, but I've always thought of one implying the other; I can't think of any case when an expression is referentially transparent but not pure, or vice-versa. Wikipedia maintains separate articles for these concepts and says: From Referential transparency : If all functions involved in the expression are pure functions, then the expression is referentially transparent. Also, some impure functions can be included in the expression if their values are discarded and their side effects are insignificant. From Pure expressions : Pure functions are required

Does Haskell have variables?

风流意气都作罢 提交于 2019-11-27 12:39:42
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. Don Stewart 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 though, but you enable them explicitly: > import Data.IORef (newIORef, readIORef, writeIORef) > v <-

How do functional languages model side-effects?

自闭症网瘾萝莉.ら 提交于 2019-11-27 12:29:40
问题 Since side-effects break referential transparency, don't they go against the point of functional languages? 回答1: There are two techniques that are used by purely functional programming languages to model side effects: 1) A world type that represents external state, where each value of that type is guaranteed by the type system to be used only once. In a language that uses this approach the function print and read might have the types (string, world) -> world and world -> (string, world)

Sampling sequences of random numbers in Haskell

跟風遠走 提交于 2019-11-27 07:28:11
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 normals function everytime I needed my list of random numbers. The problem with that must be apparent:

Is Haskell truly pure (is any language that deals with input and output outside the system)?

こ雲淡風輕ζ 提交于 2019-11-27 03:21:10
After touching on Monads in respect to functional programming, does the feature actually make a language pure, or is it just another "get out of jail free card" for reasoning of computer systems in the real world, outside of blackboard maths? EDIT: This is not flame bait as someone has said in this post, but a genuine question that I am hoping that someone can shoot me down with and say, proof, it is pure. Also I am looking at the question with respect to other not so pure Functional Languages and some OO languages that use good design and comparing the purity. So far in my very limited world

Purity vs Referential transparency

半世苍凉 提交于 2019-11-27 00:25:39
问题 The terms do appear to be defined differently, but I've always thought of one implying the other; I can't think of any case when an expression is referentially transparent but not pure, or vice-versa. Wikipedia maintains separate articles for these concepts and says: From Referential transparency: If all functions involved in the expression are pure functions, then the expression is referentially transparent. Also, some impure functions can be included in the expression if their values are

What is referential transparency?

给你一囗甜甜゛ 提交于 2019-11-26 19:10:50
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. Uday Reddy 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 semantics . The philosopher Willard Quine was responsible for initiating the concept of referential