What does apostrophe mean in Haskell?
'
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
.
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.