Skip to content

Commit 0187e2e

Browse files
authored
Add a section about fixity declarations for functions (#381)
1 parent 7f850dc commit 0187e2e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

language/Differences-from-Haskell.md

+39
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,45 @@ In PureScript, operator sections look a little bit different.
267267
(_ ^ 2)
268268
```
269269

270+
## Fixity declarations for functions
271+
272+
In Haskell, functions can have fixity declarations. For example in `base`:
273+
274+
```haskell
275+
infix4`elem`, `notElem`
276+
infixl7`quot`, `rem`, `div`, `mod`
277+
```
278+
279+
However fixity declarations are only supported while declaring [operator aliases](Syntax.md#binary-operators) for functions in PureScript. Functions are always left associative and have the highest precedence when used as infix operators, which means that:
280+
281+
```
282+
x * y `mod` z
283+
```
284+
285+
parses as:
286+
287+
```haskell
288+
((x * y) `mod` z)
289+
```
290+
291+
in Haskell, but as:
292+
293+
```purescript
294+
(x * (y `mod` z))
295+
```
296+
297+
in PureScript, and those expressions may yield different values:
298+
299+
```purescript
300+
> ((2 * 3) `mod` 5)
301+
1
302+
```
303+
304+
```purescript
305+
> (2 * (3 `mod` 5))
306+
6
307+
```
308+
270309
## Extensions
271310

272311
The PureScript compiler does not support GHC-like language extensions. However, there are some "built-in" language features that are equivalent (or at least similar) to a number of GHC extensions. These currently are:

0 commit comments

Comments
 (0)
close