Reputation
3,596
Next privilege 5,000 Rep.
Approve tag wiki edits
Badges
14 19
Newest
 Yearling
Impact
~296k people reached

Nov
10
comment What is the “Free Monad + Interpreter” pattern?
@ErikAllik: I fixed up the code and tried to explain what's going on, but I think I just made it more confusing :/.
Nov
10
comment What is the “Free Monad + Interpreter” pattern?
@ErikAllik: Ah, I think there was a mistake in my code with the (forall a. Free DSL a) argument. Either I only want it for the outside of the runIO function (with a helper function of type Free DSL a -> IO ()) or I might be able to make something similar work with ImpredicativeTypes and Free DSL (forall a. a). Since ImpredicativeTypes is poorly supported and people recommend not to use it, I'll change the code using my first approach.
Aug
20
comment What is the meaning of “doesn't compose”?
A monad is an algebraic structure with certain operations. What you described in your final paragraph is the IO type which captures "stateful actions" like keyboard input. Values of the IO type do, indeed, compose, but it's the whole type IO that is a monad. This type doesn't compose with other types that are monads like, say, the list type. That is, we can't systematically produce a type IO . List which behaves like both IO and List simultaneously. Does that make sense? I'm not sure I explained it well.
Aug
20
comment Banning zero-argument functions — what problems could it cause in a hypothetical language?
It doesn't not make sense indeed :). I was about to post an answer about OCaml, but I see you've already found it. In my experience with both Haskell and OCaml, it's a perfectly good system.
Aug
18
comment What is the “Free Monad + Interpreter” pattern?
@Porges: Good eye! I'll fix my code snippet, thanks.
May
6
comment What is the “Free Monad + Interpreter” pattern?
@AndrewThaddeusMartin: Yeah, that sounds like the best solution.
May
5
comment What is the “Free Monad + Interpreter” pattern?
@AndrewThaddeusMartin: Actually, thinking about it, I'm not sure a Return case makes sense. The only way to produce a Free DSL a with Return is Return undefined, so it would be partial no matter what. I'd have to think a bit more about what that case should actually be.
May
5
comment What is the “Free Monad + Interpreter” pattern?
@AndrewThaddeusMartin: Ah, fair point. I'll add that case in.
Apr
6
comment What is the “Free Monad + Interpreter” pattern?
@BenjaminHodgson: It makes the pattern more explicit, allows us to write reusable code and makes reasoning about it simpler. (In a sense, we can reuse reasoning just like we can reuse code!) Your intuition that it's just a matter of factoring the recursion out is correct, and it's useful just like any other sort of factoring with the added benefit of being mathematically grounded. The free package has some useful functions, for example.
Nov
7
comment What is the logic behind the use of different arrows (-> <-) in Haskell?
@Carcigenicate: Actually, you can think of list comprehensions as just a different syntax for do-notation. In fact, they used to be "monad comprehensions" by default, and now you can still enable that functionality with an extension: Monad Comprehensions.
Aug
26
comment Are null references really a bad thing?
@greenoldman: You would have some way to pattern match on the Maybe<A> value (ie do this when it has a value and that when it's null). Most languages can include this in a library with first-class functions and lambdas, and many languages have specific constructs for pattern-matching like this (ie switch on steroids).
Jul
20
comment Does javascript support numerically indexed arrays with a more optimized algorithm than an associative array?
@supercat: I'm not entirely sure exactly how slice is defined in the standard, but I suspect you're right in that it has to work with all the whole-number keys. Perhaps it also depends on the length property of the array.
Jul
20
comment Does javascript support numerically indexed arrays with a more optimized algorithm than an associative array?
@supercat: That depends on which JavaScript implementation you use. It's not part of the standard, so you can't necessarily rely on it. It's probably true for most browsers at the moment, but they might change it in the future—after all, they changed to this implementation from just returning every key in the order it was added recently, I believe.
Jun
18
comment Why are most functional programming languages also interpreted languages?
@JörgWMittag: Ah, so mixed mode is basically JIT.
Jun
18
comment Why are most functional programming languages also interpreted languages?
@JörgWMittag: Well, you have to compile to the bytecode first. Perhaps I misunderstood what you meant by mixed-mode though. The bytecode compiler is used by camlp4, but that's a bit of a historical accident and makes it slow, so they're not using it for their new "extension point" system. Mostly, the bytecode compiler is useful for portability and simplicity: for example, it's used by js_of_ocaml to compile to JavaScript. I think it's also used for the REPL.
Jun
18
comment Dealing with state problems in functional programming
Except perhaps for the database example, those problems are not inherently stateful. For example, for GUI programming, you're really using mutable state as a poor, implicit model of time; functional reactive programming lets you model time explicitly without relying on state by providing streams of events you can combine.
Jun
18
comment Why are most functional programming languages also interpreted languages?
OCaml has something like two implementations in one: a normal compiler and a bytecode compiler. The first is a normal optimizing compiler while the second is more a mixed-mode system with a bytecode interpreter. They're shipped together, but are separate backends.
Jun
3
comment What is the “Free Monad + Interpreter” pattern?
@BenjaminHodgson: Boyd is completely right. I wouldn't worry about it too much unless you're just curious. Dan Piponi gave a great talk about what "free" means at BayHac, which is worth a look. Try following along with his slides because the visual in the video is completely useless.
Jan
28
comment Why do dynamic languages make it more difficult to maintain large codebases?
@JörgWMittag: It doesn't seem to have overloaded literals the way Haskell does: it just has a few nested types of numbers. For example, you can't add your own numeric types, especially if they don't fit into the existing hierarchy. I still don't see any way to do this without either having explicit annotations or using typeclasses and inference. Besides numbers, consider things like Read which also relies on typeclases. My real point is that type systems do not just reject illegal programs. With type inference, they can make programs that would be underspecified without types work.
Jan
27
comment Why do dynamic languages make it more difficult to maintain large codebases?
A type system can actually make a language more expressive. Consider Haskell typeclasses--they enable really useful things like overloaded literals that are difficult if not impossible to replicate in other languages.