Explicitly import instances

The inability to control imports of instances is one of the trade-offs the Haskell typeclass system makes. Here’s an example in a hypothetical Haskell dialect where you can: Foo.hs: module Foo where data Foo = FooA | FooB deriving (Eq, Ord) Bar.hs: module Bar (myMap) where import Data.Map (Map) import qualified Data.Map as Map import … Read more

Is monad bind (>>=) operator closer to function composition (chaining) or function application?

Clearly, >>= is not a way to represent function composition. Function composition is simply done with .. However, I don’t think any of the articles you’ve read meant this, either. What they meant was “upgrading” function composition to work directly with “monadic functions”, i.e. functions of the form a -> m b. The technical term … Read more

Confused by the meaning of the ‘Alternative’ type class and its relationship to other type classes

To begin with, let me offer short answers to each of these questions. I will then expand each into a longer detailed answer, but these short ones will hopefully help in navigating those. No, Alternative and Monoid don’t mean different things; Alternative is for types which have the structure both of Applicative and of Monoid. … Read more

Finite comprehension of an infinite list

But since a human can prove that the sequence terminates at 4, might there be a way to get the interpreter to do it? In this simple case, yes. But there cannot exist a general algorithm to determine if an expression is true or false for all natural numbers >n for some n, because Haskell … Read more