Tag Info

New answers tagged

0

Having learned encapsulation from Borland C++ after learning C, when Borland C++ lacked templates that enabled generics, the object orientation paradigm made me uneasy. Somewhat more natural way to compute seemed filtering data through pipes. The outward stream had separate and independent identity from the inward immutable input stream, rather than be ...


1

A classifier in UML can encompass multiple subclassifiers that form something they call a "generalization set" which can be a complete partitioning of the instances of a superclass. There's a graphical notation for this in class diagrams. So, you can have a classifier C that has subclasses P Q R ... with the property that any instance of C must be an ...


6

To put it simply, the restrictions mean there are fewer correct ways to put things together, and first-class functions make it easier to factor out things like loop structures. Take the loop from this answer, for example: for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { String string = iterator.next(); if ...


3

There is no benefit from from having addItemToCart rather than ICart.AddItem. They are essentially identical. Both of those necessarily have a runtime check, because you want to be able to have a variable with any kind of Cart in it, and you won't know at compile time which one will get passed into the function. Where the benefit comes is when you first ...


1

Explanation for managers: A functional program is like one large machine where everything is connected, tubes, cables. [A car] A procedural program is like a building with rooms containing a small machine, storing partial products in bins, getting partial products from elsewhere. [A factory] So when the functional machine already fits together: it is ...


9

the underlying abstract reason for the correlation between compilation success and program correctness in functional programming? Mutable State. Compilers check things statically. They make sure your program is well formed, and the type system provides a mechanism for trying to ensure that the right sort of values are allowed in the right sort of ...


1

I don't think there's a significant correlation between functional programming compilation and runtime correctness. There may be some correlation between statically typed compilation and runtime correctness, since at least you may have the right types, if you're not casting. The programming language aspect that may somehow correlate successful compilation ...


5

You have a couple of stateful properties. Those are the registers and memory. And we have a transition between states. This is each CPU cycle. We can therefore model this architecture in a straightforward fashion: function cycle(state: State) -> State { ... } Our cycle function will treat the input state as an immutable object, and create a new state ...


2

The Unified Modeling Language is not so much unifying programming paradigms. It is dramatically focused towards object-oriented programming (hence, f.ex. its most popular diagram being the class diagram). In contrast, sum types are typically a feature of functional languages (like F#, Haskell, etc.). I'm afraid to inform you that UML is probably not a good ...


11

I can write this answer as someone who proves things a lot, so to me correctness isn't just what works, but what works and is easy to prove. In a lot of senses, functional programming is more restrictive then imperative programming. After all, nothing stops you from never mutating a variable in C! Indeed most of the features in FP languages are straight ...


0

Composition could likely be used to denote tagged unions in a UML class diagram. Composition is the "has a" relationship and a tagged union has a tag and a value. You can use multiplicity and role names or ownership indicators. However, something to consider is that class diagrams are typically geared toward representing class relationships in an ...


1

I don't recall seeing the specific Views -> Dispatcher -> Stores architecture before, but the more general concept of a "flow" has been around a while, as they mention in the article you linked: This structure allows us to reason easily about our application in a way that is reminiscent of functional reactive programming, or more specifically data-flow ...


-2

append :: [a] -> [a] -> [a] append = flip(foldr (:)) I try to explain foldr: When we use foldr (:) [1,2,3] [4,5,6] without the flip we take the second argument which is [4,5,6] the last element of the argument is 6, which we apply with the (:) to our first argument [1,2,3] which will then give us [6,1,2,3]. Next last element is 5, which we will do the ...


1

Naive reference counting cannot deal with cyclic data structures, since parts of the data structure will cause other parts to have a reference count higher than zero. On the trivial end, Lisp (in general and Common Lisp in particular) allows you to create read-time cyclic "lists": #1#=(red green blue . #1#) is a never-ending list. They're even useful, in ...


8

Reference counting is basically never sufficient for managing memory due to cycles. If a language has mutation we can essentially create a structure like ------------------- | | | | Head | Tail | | | | ------------------- | | | | +-------+ | 1 <+ I put way too much effort into this ...


-1

Environment fragments in Lisp have an undetermined lifetime, most of the LISP implementations need garbage collection to reclaim free run-time store.


1

I think that the existing answers are quite good. I would like to elaborate on some aspects that IMO have not been stressed enough. In mathematics a function is just a mapping from a tuple of values to a value. So, given a function f and a value x, f(x) will always be the same result y. You may well replace f(x) with y everywhere in an expression and ...



Top 50 recent answers are included