Saturday, July 30, 2011

Haskell_Notes_2

2. Starting Out
==========

After the installation in Windows:

C:\Program Files\Haskell Platform\2011.2.0.1\winghci\winghci.exe


double click and run.


GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> 


Few Points:

1. GHCi -> Glasgow Haskell Compiler interactive mode
2. Latest version as of 30th July 2011 - 7.0.3
3. Couple of packages are loaded - ghc-prim, integer-gmp, base, ffi-1.0
4. The default prompt we get is: Prelude
-------------------------------

Prelude> :set prompt ghci
ghci :set prompt "ghci> "
"ghci> " :set prompt ghci> 
ghci>  
---------------------------------
ghci>  180

180
ghci>  1*0
0
ghci>  1/0
Infinity
ghci>  10/3
3.3333333333333335
ghci>  10/4
2.5
ghci>  1==0
False
ghci>  10000000.0000000000001==10000000.0000000000001
True
ghci>  10000000.0000000000001==10000000.0000000000000 
True
ghci>  10000000.0000000000001==10000000.0000000000000000
True
ghci>  10000000.0000000000001==10000000.0000000000000001
True
ghci>  10000000.0000000000001==10000000.0000000100000001
False
ghci>  10000000.0000000000001==10000000.0000000000001
True
ghci>  10000000.0000000000001==10000000.0000000000009
True



ghci>  10+100/20
15.0
ghci>  (10+100)/20
5.5
ghci>  5 * -3


<interactive>:1:1:
    Precedence parsing error
        cannot mix `*' [infixl 7] and prefix `-' [infixl 6] in the same infix expression


ghci>  5 * (-3)
-15
ghci>

Boolean algebra

ghci>  true


<interactive>:1:1: Not in scope: `true'


ghci>  True
True


ghci>  True & True

<interactive>:1:6: Not in scope: `&'
ghci>  True && True
True
ghci>  True &&& True

<interactive>:1:6: Not in scope: `&&&'
ghci>  True && && True

<interactive>:1:9: parse error on input `&&'
ghci>  True &&           True
True
ghci>  True &&       False    True

<interactive>:1:15:
    The function `False' is applied to one argument,
    but its type `Bool' has none
    In the second argument of `(&&)', namely `False True'
    In the expression: True && False True
    In an equation for `it': it = True && False True

True 
False
&&
||
not

Case Sensitive


Comment? 


-------------------------------

Character Type:    'a' 
string type: "hello"

Equal to and Not Equal to:
ghci> 1==1
True
ghci> 1/=1
False
ghci> 1/=2
True

Exceptions:
ghci>  5 == True

<interactive>:1:1:
    No instance for (Num Bool)
      arising from the literal `5'
    Possible fix: add an instance declaration for (Num Bool)
    In the first argument of `(==)', namely `5'
    In the expression: 5 == True
    In an equation for `it': it = 5 == True
ghci>  'a' + 'b'

<interactive>:1:5:
    No instance for (Num Char)
      arising from a use of `+'
    Possible fix: add an instance declaration for (Num Char)
    In the expression: 'a' + 'b'
    In an equation for `it': it = 'a' + 'b'
ghci>  "he" + "he"

<interactive>:1:6:
    No instance for (Num [Char])
      arising from a use of `+'
    Possible fix: add an instance declaration for (Num [Char])
    In the expression: "he" + "he"
    In an equation for `it': it = "he" + "he"




No comments:

Post a Comment