Hot answers tagged

38

There are lots of languages which already work this way, e.g. Haskell. In Haskell, every function takes exactly one argument and returns exactly one value. It is always possible to replace a function that takes n arguments with a function that takes n-1 arguments and returns a function that takes the ultimate argument. Applying this recursively, it is ...


37

Robert C. Martin in his book "Clean Code" recommends heavily the use of functions with 0, 1 or 2 parameters at maximum, so at least there is one experienced book author who thinks code becomes cleaner by using this style (however, he is surely not the ultimative authority here, and his opinions are debatable). Where Bob Martin is IMHO correct is that ...


7

I've been spending some time these last few weeks attempting to learn the J computer language. In J, pretty much everything is an operator, so you only get "monads" (functions that have only one argument) and "dyads" (functions with exactly two arguments). If you need to more arguments, you have to either provide them in an array, or provide them in "boxes"...


7

I think what you’ve picked up on is that, in a referentially transparent language, everything has value semantics. And if you don’t read or write globals, or do I/O, then indeed this is enough to give you referential transparency. If, in addition, you don’t use local mutation, then you’ll also get more of the benefits of equational reasoning. And, for ...


6

Scala is an object-oriented language. In object-oriented languages, methods have special access to a designated "receiver" argument (typically called this or self). This parameter is usually not made explicit in the method signature (Python is an exception). So, you have to remember that the map method is actually defined as a member of a trait or class and ...


5

A Map is precisely the right base data structure here. I'm not sure why it would make you uneasy. It has good lookup and update times, it's dynamic in size, and it's very easy to create derivative data structures from. For example (in haskell): filterWithKey (\k _ -> (snd k) == column) -- All pieces in given column filterWithKey (\k _ -> (fst k) == ...


5

I've done this recently in F# and I ended up using a one-dimensional list (in F#, that's a single-linked list). In practice, the speed of O(n) list indexer is not a bottleneck for human-usable board sizes. I experimented with other types like 2d array, but in the end, it was the trade-off of either writing my own value-equality-checking code or a translation ...


4

Yes, they're equivalent in the sense that the Option type together with Option.bind and type constructor Some constitute a monad. While monads (as in the Monad typeclass) are a central part of Haskells identity, from a conceptual point of view they're a language-agnostic construct. A design pattern if you like. If you have a type, and you have a bind and a ...


4

Pointers are orthogonal to referential transparency. Move semantics works fine in C, although with more boilerplate than C++. No mutable global state + no function permitted to mutate it's arguments would suffice for referential transparency, even when passing by pointer. Just don't hack up anything passed in. Mutating local variables is fine - the caller ...


4

I'm more interested in answering the questions within your post, or rather the source of your confusion. As for the question in the title: are promises functional? yes they can be. See this page for promises in Haskell, which is the prototypical pure functional programming lanugage. Your confusion as to the side-effecting nature of promises is well ...


4

A language based around how it constrains the developer is dependent on the assumption that the language developer understands the needs of each programmer better than the programmer understands those needs themselves. There are cases where this is actually valid. For example, the constraints on multithreaded programming requiring synchronization using ...


3

A comonad is, just like a monad, a mathematical structure in category theory. The co-prefix is very common there to denote "inverses" as you put it (although I don't think pure mathematicians agree on the choice of word). In category theory there are categories, which are briefly put a collection of objects (of any type or nature, the internal structure is ...


3

Following Doc Brown's advice, I've cobbled together an answer from the comments I had posted on this page. In my experience, the theoretical selling point behind workflow systems is that you don't need software developers to use them or update them. You simply point your Business Analyst or Subject Matter Expert at them and voila!, you have a working system....


3

They're cool and they're new and (most importantly) some companies decided they were expensive and attracted a large amount of commission to anyone who sold them. Hence we went through a period where workflow engines were de rigeur. Unless you have specific and tightly focussed requirements where a workflow engine would be beneficial, they are terrible ...


2

What makes Idris so unique is its first class dependent typing. This vastly reduces the number of possibilities compared to weaker type systems, and makes the inference easier to compute. Also, I think it just hasn't been explored much. People who create functional languages tend to get excited about mathematics and not so much about tooling. After ...


2

It is possible, in general, to analyse the parse tree of a function and check a set of constraints that ensure we know if the function is definitely pure: If the function only calls other functions that are pure And doesn't reference or modify any global variables Then it is pure. There is, however, a problem with doing this in Javascript (and many ...


2

There are three parts in this type signature: Current, original type, T Return type, U Transformation, f: (T) => U Since you're looking at a generic class with a map method (as opposed to just a stand-alone function), the T type variable is defined above, in a class type signature: Try[T]. This explains why there's no T inside bracket of map[...]. It'...


1

You will need two things: Closure Composite data type I will add a mathematical example to explain the answer written by Jörg W Mittag. Consider the Gaussian function. A Gaussian function has two parameters for its shape, namely the mean (center position of the curve) and the variance (related to the pulse width of the curve). In addition to the two ...


1

From my little understanding, a comonad is a Rube Goldberg machine to do post-docs: http://www.willamette.edu/~fruehr/haskell/evolution.html ...sorry, I couldn't resist it.


1

They're equivalent, and they're both monads. The difference is being a monad means something in Haskell - there's an explicit Monad typeclass and "do notation" can be used to eliminate a lot of boilerplate when writing monadic code. In F#, builder notation and let! and do! can be used to get rid of similar boilerplate, but there is not an explicit notion of ...



Only top voted, non community-wiki answers of a minimum length are eligible