Difference between revisions of "FP Laboratory 2"

From Marek Běhálek Wiki
Jump to navigation Jump to search
Line 3: Line 3:
 
#Using the GHCi command <code>:info</code>, learn the type of the following functions (and operators): <code>+, sqrt, succ, max</code>
 
#Using the GHCi command <code>:info</code>, learn the type of the following functions (and operators): <code>+, sqrt, succ, max</code>
 
#Using the command <code>:set +t</code> it is possible to get the information about the type of the evaluated expressions. With this setting on evaluate expressions:
 
#Using the command <code>:set +t</code> it is possible to get the information about the type of the evaluated expressions. With this setting on evaluate expressions:
#*5 + 8 No comments
+
<syntaxhighlight lang="Haskell" >
#*3 * 5 + 8 No comments
+
5 + 8  
#*2 + 4 No comments
+
3 * 5 + 8
#*sqrt 16 No comments
+
2 + 4
#*succ 6 No comments
+
sqrt 16  
#*succ 7 No comments
+
succ 6
#*pred 9 No comments
+
succ 7
#*pred 8 No comments
+
pred 9
#*sin (pi / 2) No comments
+
pred 8
#*truncate pi No comments
+
sin (pi / 2)
#*round 3.5 No comments
+
truncate pi
#*round 3.4 No comments
+
round 3.5
#*floor 3.7 No comments
+
round 3.4  
#*ceiling 3.3 No comments
+
floor 3.7  
 +
ceiling 3.3
 +
</syntaxhighlight>

Revision as of 12:09, 12 September 2019

Types

  1. Using the GHCi command :info, learn the type of the following functions (and operators): +, sqrt, succ, max
  2. Using the command :set +t it is possible to get the information about the type of the evaluated expressions. With this setting on evaluate expressions:
5 + 8 
3 * 5 + 8
2 + 4
sqrt 16 
succ 6
succ 7
pred 9
pred 8
sin (pi / 2)
truncate pi
round 3.5
round 3.4 
floor 3.7 
ceiling 3.3