Difference between revisions of "FP Laboratory 1"
Jump to navigation
Jump to search
Line 6: | Line 6: | ||
===How to verify it is working?=== | ===How to verify it is working?=== | ||
− | *Run <code>ghci</code> from the command line. | + | *Run <code>ghci</code> from the command line. it will start GHC Interpreter, the output should be something like this: |
</translate> | </translate> | ||
<syntaxhighlight lang="Haskell" class="myDark" > | <syntaxhighlight lang="Haskell" class="myDark" > | ||
Line 13: | Line 13: | ||
</syntaxhighlight > | </syntaxhighlight > | ||
<translate> | <translate> | ||
− | + | *If you write expression, for example <code>1+2*3</code>, it should be evaluated. You can close this interpreter by typing<code>:q</code>. | |
== Topic == | == Topic == |
Revision as of 12:12, 28 August 2019
Working environment
Using the installation guide from Functional programming prepare your working environment.
How to verify it is working?
- Run
ghci
from the command line. it will start GHC Interpreter, the output should be something like this:
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
Prelude>
- If you write expression, for example
1+2*3
, it should be evaluated. You can close this interpreter by typing:q
.
Topic
ghci> :l baby
[1 of 1] Compiling Main ( baby.hs, interpreted )
Ok, modules loaded: Main.
ghci> doubleMe 9
18
ghci> doubleMe 8.3
16.6
ghci> 2 + 15
17
ghci> 49 * 100
4900
ghci> 1892 - 1472
420
ghci> 5 / 2
2.5
ghci> import Prelude
doubleSmallNumber x = if x > 100
then x
else x*2
ghci> [1,2,3,4] ++ [9,10,11,12]
[1,2,3,4,9,10,11,12]
ghci> "hello" ++ " " ++ "world"
"hello world"
ghci> ['w','o'] ++ ['o','t']
"woot"
multThree :: (Num a) => a -> a -> a -> a
multThree x y z = x * y * z