You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/02_functions-types.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,16 +72,16 @@ Declaration of a function is simple, just use the prefix notation as you would c
72
72
fibonacci::Word->Integer
73
73
fibonacci 0=1
74
74
fibonacci 1=1
75
-
fibonacci n =(fibonacci n-1) +(fibonacci n-2)
75
+
fibonacci n = fibonacci (n-1) + fibonacci (n-2)
76
76
```
77
77
78
78
### Type declaration
79
79
80
80
There are three basic ways how to introduce your own data type:
81
81
82
-
1. type synonym = you just use a different name for some existing type (for example `String` is type synonym for `[Char]` = list of `Char`)
83
-
2. new data type = declare type with type constructor (before `=`) and one or more data constructors (after `=`, separated by `|`), you may use typeclass constraints, type variables, and recursion
84
-
3. newtype = new data type with exactly one data constructor with one parameter (new type is isomorphic with the "wrapped" type and compiler can do optimizations, can be used also in another way in more advanced code)
82
+
1.`type` synonym = you just use a different name for some existing type (for example `String` is type synonym for `[Char]` = list of `Char`)
83
+
2. new `data` type = declare type with type constructor (before `=`) and one or more data constructors (after `=`, separated by `|`), you may use typeclass constraints, type variables, and recursion
84
+
3.`newtype` = new data type with exactly one data constructor with one parameter (new type is isomorphic with the "wrapped" type and compiler can do optimizations, can be used also in another way in more advanced code)
85
85
86
86
```haskell
87
87
typeString= [Char]
@@ -125,7 +125,7 @@ Haskell has a strong static type system which is one of the things making it so
125
125
*`Word` = Unsigned integral number (same size as `Int`)
126
126
*`Char` = Unicode character (ISO/IEC 10646)
127
127
*`Bool` = truth value, only `True` or `False`
128
-
*`String` = literally list of characters
128
+
*`String` = literally list of characters (type synonym for `[Char]`)
129
129
130
130
### Type and data constructor
131
131
@@ -288,7 +288,7 @@ myFunc (a, b, c, d) = (if d then a + d else a - d, b)
288
288
289
289
There are basic functions for tuples with two elements: `fst`, `snd`, and `swap`.
0 commit comments