Questions tagged [haskell]

Haskell is a functional programming language featuring strong static typing, lazy evaluation, extensive parallelism and concurrency support, and unique abstraction capabilities.

74 questions
5
votes
1 answer

How does Bifunctor in Haskell work?

I was reading 'Category Theory for Programmers' by Bartosz Milewski and got really confused by the implementation of bimap in Bifunctor typeclass. class Bifunctor f where bimap :: (a -> c) -> (b -> d) -> f a b -> f c d bimap g h = first g .…
Qiu Haohao
  • 53
  • 3
3
votes
3 answers

Can Haskell ensure a Functor (or other typeclasses) satisfies its law?

It seems that Functor definitions in Haskell can be accepted if the type is correct. This code compiles, but it doesn't satisfy the functor law: data Bst a = NIL | Node a (Bst a) (Bst a) deriving (Eq, Ord, Show) instance Functor Bst where fmap _…
ice1000
  • 940
  • 6
  • 35
2
votes
1 answer

Haskell type of lambda expressions

I'm new to Haskell and have some general questions. Question 1: The Haskell expression (\x -> \x -> x) is the same as the λ-term λx.λx.x The type of this expression is p1 -> p2 -> p2. What does this mean? Question 2: λyx.x is shorthand for λy.λx.x.…
Kingvinst
  • 21
  • 1
1
vote
1 answer

Haskell type class and initial algebra

For the example below, I am trying to understand how Haskell type classes, type class instances, and data types relate to the concept of initial algebra. There are two Haskell data types sharing a pair of operations for equality and addition. From…
Patrick Browne
  • 339
  • 1
  • 9
0
votes
1 answer

Understanding arguments in Haskell type classes and instances

I am trying to understand a Haskell class declaration and instance from a paper. I am trying to understand the class declaration: class (Surfaces v o, Paths a b (v o)) => Vehicles v o a b My current understanding is that the first occurance of…
Patrick Browne
  • 339
  • 1
  • 9
0
votes
0 answers

Haskell: difference behavior in ghci concerning ``polymorphic recursion''

I stumbled upon some question that puzzled me, maybe it's just a feature (or simply because I am doing first ``Haskell-steps'' without studying the manual too deeply, which I guess I should... Anyway, the observation want to ask about is as follows:…
0
votes
0 answers

Data types a la carte -- over-engineered?

I'm working through Swierstra's 2008 paper. I'm up to Section 3 eval addExample, just before 'Automating injections'. And boy! does it need automating. Is it just me, or is the whole thing over-engineered? Compare this in the paper addExample ::…
AntC
  • 487
  • 3
  • 15