Questions tagged [haskell]
Haskell is a purely functional programming language featuring strong static typing, lazy evaluation, extensive parallelism and concurrency support, and unique abstraction capabilities.
haskell
51,238
questions
1689
votes
48
answers
329k
views
What is a monad?
Having briefly looked at Haskell recently, what would be a brief, succinct, practical explanation as to what a monad essentially is?
I have found most explanations I've come across to be fairly ...
930
votes
6
answers
97k
views
What part of Hindley-Milner do you not understand?
I swear there used to be a T-shirt for sale featuring the immortal words:
What part of
do you not understand?
In my case, the answer would be... all of it!
In particular, I often see notation like ...
921
votes
5
answers
241k
views
A monad is just a monoid in the category of endofunctors, what's the problem?
Who first said the following?
A monad is just a monoid in the
category of endofunctors, what's the
problem?
And on a less important note, is this true and if so could you give an explanation (...
803
votes
14
answers
213k
views
What is the difference between . (dot) and $ (dollar sign)?
What is the difference between the dot (.) and the dollar sign ($)?
As I understand it, they are both syntactic sugar for not needing to use parentheses.
754
votes
15
answers
273k
views
Getting started with Haskell
For a few days I've tried to wrap my head around the functional programming paradigm in Haskell. I've done this by reading tutorials and watching screencasts, but nothing really seems to stick.
Now, ...
742
votes
17
answers
160k
views
Speed comparison with Project Euler: C vs Python vs Erlang vs Haskell
I have taken Problem #12 from Project Euler as a programming exercise and to compare my (surely not optimal) implementations in C, Python, Erlang and Haskell. In order to get some higher execution ...
562
votes
8
answers
62k
views
Large-scale design in Haskell? [closed]
What is a good way to design/structure large functional programs, especially in Haskell?
I've been through a bunch of the tutorials (Write Yourself a Scheme being my favorite, with Real World Haskell ...
548
votes
10
answers
247k
views
What is Haskell used for in the real world? [closed]
There is a lot of hype around Haskell, however, it is hard to get information on how it is used in the real world applications. What are the most popular projects / usages of Haskell and why it excels ...
424
votes
7
answers
68k
views
What are free monads?
I've seen the term Free Monad pop up every now and then for some time, but everyone just seems to use/discuss them without giving an explanation of what they are. So: what are free monads? (I'd say I'...
420
votes
15
answers
80k
views
Is functional GUI programming possible? [closed]
I've recently caught the FP bug (trying to learn Haskell), and I've been really impressed with what I've seen so far (first-class functions, lazy evaluation, and all the other goodies). I'm no expert ...
408
votes
8
answers
61k
views
Why do we need monads?
In my humble opinion the answers to the famous question "What is a monad?", especially the most voted ones, try to explain what is a monad without clearly explaining why monads are really necessary. ...
394
votes
1
answer
22k
views
Transitivity of Auto-Specialization in GHC
From the docs for GHC 7.6:
[Y]ou often don't even need the SPECIALIZE pragma in the first place. When compiling a module M, GHC's optimiser (with -O) automatically considers each top-level ...
382
votes
8
answers
62k
views
What does the `forall` keyword in Haskell/GHC do?
I'm beginning to understand how the forall keyword is used in so-called "existential types" like this:
data ShowBox = forall s. Show s => SB s
This is only a subset, however, of how ...
355
votes
4
answers
29k
views
What does "coalgebra" mean in the context of programming?
I have heard the term "coalgebras" several times in functional programming and PLT circles, especially when the discussion is about objects, comonads, lenses, and such. Googling this term gives pages ...
353
votes
7
answers
42k
views
Good Haskell source to read and learn from [closed]
What are some open source programs that use Haskell and can be considered to be good quality modern Haskell? The larger the code base, the better.
I want to learn from their source code. I feel I'm ...
345
votes
7
answers
31k
views
Abusing the algebra of algebraic data types - why does this work?
The 'algebraic' expression for algebraic data types looks very suggestive to someone with a background in mathematics. Let me try to explain what I mean.
Having defined the basic types
Product •
...
340
votes
3
answers
77k
views
Why is Haskell (GHC) so darn fast?
Haskell (with the GHC compiler) is a lot faster than you'd expect. Used correctly, it can get close-ish to low-level languages. (A favorite thing for Haskellers to do is to try and get within 5% of C (...
330
votes
2
answers
13k
views
Extremely small or NaN values appear in training neural network
I'm trying to implement a neural network architecture in Haskell, and use it on MNIST.
I'm using the hmatrix package for linear algebra.
My training framework is built using the pipes package.
My code ...
324
votes
9
answers
43k
views
What is Weak Head Normal Form?
What does Weak Head Normal Form (WHNF) mean? What does Head Normal form (HNF) and Normal Form (NF) mean?
Real World Haskell states:
The familiar seq function evaluates an expression to what we
call ...
323
votes
2
answers
11k
views
Techniques for Tracing Constraints
Here's the scenario: I've written some code with a type signature and GHC complains could not deduce x ~ y for some x and y. You can usually throw GHC a bone and simply add the isomorphism to the ...
307
votes
3
answers
38k
views
What does the exclamation mark mean in a Haskell declaration?
I came across the following definition as I try to learn Haskell using a real project to drive it. I don't understand what the exclamation mark in front of each argument means and my books didn't ...
270
votes
6
answers
27k
views
What's so bad about Template Haskell?
It seems that Template Haskell is often viewed by the Haskell community as an unfortunate convenience. It's hard to put into words exactly what I have observed in this regard, but consider these few ...
269
votes
1
answer
12k
views
How fundamentally different are push-pull and arrowized FRP?
I want to study FRP in Haskell, but it's a bit difficult to decide on a library to use.
Many seem to be dead attempts, some seem to have been resurrected (such as recent activity on Yampa).
From what ...
266
votes
1
answer
43k
views
Haskell: Lists, Arrays, Vectors, Sequences
I'm learning Haskell and read a couple of articles regarding performance differences of Haskell lists and (insert your language)'s arrays.
Being a learner I obviously just use lists without even ...
259
votes
1
answer
6k
views
Getting associated type synonyms with template Haskell
Can Template Haskell find out the names and/or the declarations of the associated type synonyms declared in a type class? I expected reify would do what I want, but it doesn't seem to provide all the ...
244
votes
4
answers
238k
views
Haskell: Converting Int to String
I know you can convert a String to an number with read:
Prelude> read "3" :: Int
3
Prelude> read "3" :: Double
3.0
But how do you grab the String representation of an Int value?
236
votes
2
answers
34k
views
Difference between `data` and `newtype` in Haskell
What is the difference when I write this?
data Book = Book Int Int
versus
newtype Book = Book (Int, Int) -- "Book Int Int" is syntactically invalid
235
votes
4
answers
33k
views
Comparing Haskell's Snap and Yesod web frameworks
The two Haskell web frameworks in the news recently are Yesod (at 0.8) and Snap (at 0.4).
It's quite obvious that Yesod currently supports a lot more features than Snap. However, I can't stand the ...
234
votes
5
answers
20k
views
Good examples of Not a Functor/Functor/Applicative/Monad?
While explaining to someone what a type class X is I struggle to find good examples of data structures which are exactly X.
So, I request examples for:
A type constructor which is not a Functor.
A ...
226
votes
7
answers
50k
views
What is the Haskell response to Node.js?
I believe the Erlang community is not envious of Node.js as it does non-blocking I/O natively and has ways to scale deployments easily to more than one processor (something not even built-in in Node....
219
votes
6
answers
34k
views
Running a Haskell program on the Android OS
Forenote: This is an extension of the thread started on /r/haskell
Lets start with the facts:
Android is one awesome Operating System
Haskell is the best programming language on the planet
...
213
votes
2
answers
7k
views
When is -XAllowAmbiguousTypes appropriate?
I've recently posted a question about syntactic-2.0 regarding the definition of share. I've had this working in GHC 7.6:
{-# LANGUAGE GADTs, TypeOperators, FlexibleContexts #-}
import Data.Syntactic
...
211
votes
3
answers
26k
views
What is the difference between traits in Rust and typeclasses in Haskell?
Traits in Rust seem at least superficially similar to typeclasses in Haskell, however I've seen people write that there are some differences between them. I was wondering exactly what these ...
207
votes
5
answers
19k
views
Are there pronounceable names for common Haskell operators? [closed]
I'm reading Learn You a Haskell for Great Good, and I never know how to pronounce the Haskell operators. Do they have "real" names? ?
For instance, how do you read aloud an expression like this one?
...
205
votes
4
answers
19k
views
Reading GHC Core
Core is GHC's intermediate language. Reading Core can help you better understand the performance of your program. Someone asked me for documentation or tutorials on reading Core, but I couldn't find ...
202
votes
6
answers
93k
views
What is the difference between Int and Integer?
In Haskell, what is the difference between an Int and an Integer? Where is the answer documented?
202
votes
3
answers
5k
views
What is an appropriate type for smart contracts?
I'm wondering what is the best way to express smart contracts in typed languages such as Haskell or Idris (so you could, for example, compile it to run on the Ethereum network). My main concern is: ...
198
votes
15
answers
193k
views
How to split a string in Haskell?
Is there a standard way to split a string in Haskell?
lines and words work great from splitting on a space or newline, but surely there is a standard way to split on a comma?
I couldn't find it on ...
198
votes
3
answers
12k
views
What optimizations can GHC be expected to perform reliably?
GHC has a lot of optimizations that it can perform, but I don't know what they all are, nor how likely they are to be performed and under what circumstances.
My question is: what transformations can ...
194
votes
7
answers
87k
views
How to define a function in ghci across multiple lines?
I'm trying to define any simple function that spans multiple lines in ghci, take the following as an example:
let abs n | n >= 0 = n
| otherwise = -n
So far I've tried pressing Enter ...
187
votes
8
answers
23k
views
Why are side-effects modeled as monads in Haskell?
Could anyone give some pointers on why the impure computations in Haskell are modelled as monads?
I mean monad is just an interface with 4 operations, so what was the reasoning to modelling side-...
178
votes
1
answer
18k
views
lenses, fclabels, data-accessor - which library for structure access and mutation is better
There are at least three popular libraries for accessing and manipulating fields of records. The ones I know of are: data-accessor, fclabels and lenses.
Personally I started with data-accessor and I'...
173
votes
7
answers
45k
views
Implications of foldr vs. foldl (or foldl')
Firstly, Real World Haskell, which I am reading, says to never use foldl and instead use foldl'. So I trust it.
But I'm hazy on when to use foldr vs. foldl'. Though I can see the structure of how ...
173
votes
2
answers
23k
views
Why are λ-calculus optimal evaluators able to compute big modular exponentiations without formulas?
Church numbers are an encoding of natural numbers as functions.
(\ f x → (f x)) -- church number 1
(\ f x → (f (f (f x)))) -- church number 3
(\ f x → (f (f (f (f x))))) -- church ...
170
votes
4
answers
42k
views
Why is there "data" and "newtype" in Haskell? [duplicate]
It seems that a newtype definition is just a data definition that obeys some restrictions (e.g., only one constructor), and that due to these restrictions the runtime system can handle newtypes more ...
169
votes
4
answers
16k
views
Why not be dependently typed?
I have seen several sources echo the opinion that "Haskell is gradually becoming a dependently-typed language". The implication seems to be that with more and more language extensions, Haskell is ...
168
votes
5
answers
45k
views
Multi-line commands in GHCi
I am having problem in entering multi-line commands in ghci.
The following 2-line code works from a file:
addTwo :: Int -> Int -> Int
addTwo x y = x + y
But when I enter in ghci, I get an ...
165
votes
3
answers
51k
views
What is the difference between Cabal and Stack?
Yesterday I learnt about a new Haskell tool called Stack. At the first blush, it looks like it does much the same job as Cabal. So, what is the difference between them? Is stack a replacement for ...
164
votes
7
answers
130k
views
Difference between `mod` and `rem` in Haskell
What exactly is the difference between mod and rem in Haskell?
Both seems to give the same results
*Main> mod 2 3
2
*Main> rem 2 3
2
*Main> mod 10 5
0
*Main> rem 10 5
0
*Main> mod 1 0
...
163
votes
1
answer
14k
views
What's the status of multicore programming in Haskell?
What's the status of multicore programming in Haskell? What projects, tools, and libraries are available now? What experience reports have there been?