Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does apostrophe mean in Haskell?

Tags:

haskell

Sometimes I see code with the following expression:

example = example' []

Or what is the different between these functions?

foldl
foldl'
like image 702
XIA Yang Avatar asked Apr 28 '12 11:04

XIA Yang


2 Answers

' is simply another identifier character like any other. foldl' is a completely separate function from foldl; it could just as well be called strictFold. It's called that because it's closely related to foldl: it's a foldl where the accumulator is evaluated at every step, so that large thunks don't build up. For instance, foldl (+) 0 will overflow the stack on a large list, but foldl' (+) 0 won't.

In general, the suffixing of a ' means one of three things: foo' is either a helper definition made for the purpose of defining foo, a modified version of foo (that is, state, state', and state'' could be an initial state and two updated versions), or a strict version of foo.

like image 117
ehird Avatar answered Sep 25 '22 17:09

ehird


Nothing, at least not in that context, since an apostrophe is a valid identifier character (see this answer for some more detail.)

It is a bit of a convention in the standard libraries that a strict version of certain functions is differentiated from the standard (lazy) version by an apostrophe, such as foldl' (strict) and foldl (lazy). This has nothing to do with the apostrophe being special though, it's just a convention.

like image 28
huon Avatar answered Sep 25 '22 17:09

huon