Difference between revisions of "FP Laboratory 1"

From Marek Běhálek Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
<translate>
 
<translate>
 
== Topic ==
 
== Topic ==
<syntaxhighlight lang="Haskell" style="background-color: black !important;" >
+
<syntaxhighlight lang="Haskell" style=" background: #282a36; color: #f8f8f2 " >
 
ghci> :l baby   
 
ghci> :l baby   
 
[1 of 1] Compiling Main            ( baby.hs, interpreted )   
 
[1 of 1] Compiling Main            ( baby.hs, interpreted )   

Revision as of 12:12, 12 August 2019

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