In Haskell, why isn’t there a TypeClass for things that can act like lists?

The ListLike package seems to provide what you’re looking for. I’ve never understood why it isn’t more popular. ListLike aside, one reason this isn’t implemented in the Prelude is because it’s not possible to do so well without invoking some language extensions (multi-param type classes and fundeps or associated types). There are three sorts of … Read more

How would I translate a Haskell type class into F#?

My brief answer is: OO is not powerful enough to replace type classes. The most straightforward translation is to pass a dictionary of operations, as in one typical typeclass implementation. That is if typeclass Foo defines three methods, then define a class/record type named Foo, and then change functions of Foo a => yadda -> … Read more

Using Eithers with Scala “for” syntax

It doesn’t work in scala 2.11 and earlier because Either is not a monad. Though there’s talk of right-biasing it, you can’t use it in a for-comprehension: you have to get a LeftProject or RightProjection, like below: for { foo <- Right[String,Int](1).right bar <- Left[String,Int](“nope”).right } yield (foo + bar) That returns Left(“nope”), by the … Read more

Functions with generic parameter types

Overloading is typically the bugaboo of type-inferenced languages (at least when, like F#, the type system isn’t powerful enough to contain type-classes). There are a number of choices you have in F#: Use overloading on methods (members of a type), in which case overloading works much like as in other .Net languages (you can ad-hoc … Read more