Sets, Functors and Eq confusion

Another argument against Set being a Functor – it is widely accepted that being a Functor allows you to transform the “elements” of a “collection” while preserving the shape. […] Clearly, any functor instance for Set has the possibility to change the shape, by reducing the number of elements in the set. I’m afraid that … Read more

Why use functors over functions?

At least four good reasons: Separation of concerns In your particular example, the functor-based approach has the advantage of separating the iteration logic from the average-calculation logic. So you can use your functor in other situations (think about all the other algorithms in the STL), and you can use other functors with for_each. Parameterisation You … Read more

Why can’t I define a function inside another function?

It is not obvious why one is not allowed; nested functions were proposed a long time ago in N0295 which says: We discuss the introduction of nested functions into C++. Nested functions are well understood and their introduction requires little effort from either compiler vendors, programmers, or the committee. Nested functions offer significant advantages, […] … Read more

Why should I use applicative functors in functional programming?

Applicative functors are a construction that provides the midpoint between functors and monads, and are therefore more widespread than monads, while more useful than functors. Normally you can just map a function over a functor. Applicative functors allow you to take a “normal” function (taking non-functorial arguments) use it to operate on several values that … Read more

Monads as adjunctions

Edit: Just for fun, I’m going to do this right. Original answer preserved below The current adjunction code for category-extras now is in the adjunctions package: http://hackage.haskell.org/package/adjunctions I’m just going to work through the state monad explicitly and simply. This code uses Data.Functor.Compose from the transformers package, but is otherwise self-contained. An adjunction between f … Read more

F# changes to OCaml [closed]

This question has been answered for some time now, but I was quite surprised that most of the answers say what OCaml features are missing in F# – this is definitely good to know if you want to port existing OCaml programs to F# (which is probably the motivation of most of the referenced articles). … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)