Haskell Video Tutorials :
Newbie Tutorial on Haskell
Introduction on Data.Map
How to load .hs files using Haskell GHCI compiler?
1. Run GHC
2. Load File Location
3. Load .hs file
4. Run your function
Explanation on the 4 Steps to load .hs into GHC
Below is the explanation for the four steps above to understand the steps in-depth.
Run GHC (GHC is short for Glasgow Haskell Compiler Interface)
If you do not have GHC installed, you could download it from here
For those who are interested in Window Haskell Compiler (WinHugs), download it from here
Locate where your .hs file is saved. For example, I created my code using notepad and saved it as ayumilove.hs (with the .hs file extension) in c:\program files\haskell. The location that I am referring to is the c:\program files\haskell. Next, you need to load that file location into GHC. To do complete step 2, you need to type in this command line (without double quotes) “:cd YourHsLocation”. In my case, I would type into GHC as “:cd c:\program files\haskell”. The reason to complete step 2 is to acknowledge GHC that ayumilove.hs file is located in that folder/place I saved.
Once you have pointed out to GHC on .hs file location, you need to load your .hs file into GHC too. To do this, type this command line (without double qoutes) “:load yourhsfilename”. In my case, my .hs file is called ayumilove.hs, so I will type this “:load ayumilove” without the .hs file extension!. Another example would be, if my .hs file is called calculator.hs, I would type it as “:load calculator”. If you encounter an error message here, this means the code in your .hs needs to be corrected before able reload the file perfectly in GHC.
Finally, you can now run your function that you have written in your .hs file. Example, if my calculator.hs has sumNumber function that takes in 2 Int parameters, I would just need to type in the function name and input 2 values like this (without double quotes) “sumNumber 3 5″. GHC would compute and sum those number (3 + 5 = 8 ) and generate the result 8 on the next new line. Most common mistake that newbie does is forget to include the function first before inputing the values.
The area of a triangle with sides a, b, c is given by the formula
squareroot(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2.
Design a haskell program to calculate the area of a triangle.
areaTriangle :: Float -> Float -> Float -> Float
areaTriangle a b c =
let s = (a+b+c)/2
in sqrt (s * ( s – a ) * ( s – b ) * ( s – c ))