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.
Step 1:

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

Step 2:

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.

Step 3:

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.

Step 4:

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.

Exercise 1
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 ))

8 responses to “Haskell”

  1. Cheap Windows 7 Home Premium Activation Key says :

    Somebody essentially lend a hand to make seriously articles I might state. This is the first time I frequented your website page and up to now? I surprised with the research you made to create this actual publish extraordinary. Wonderful task!

  2. bob says :

    what if the triangle you entered had the sides of 1 2 and 4?

  3. DhaVhe says :

    Thank you so much!!

    Your videos and explanation about Haskell are a very good introduction for those who are just starting on this language.

    Now i’m ready to learn an advanced guide.

    Good work, keep it that way!!
    Greetings from Mexico.

  4. yunus says :

    l watched your videos l like them. thank you my friend

  5. strongdevil says :

    Thank you so much for your instructions, Ayu.

    I am waiting for other videos regarding haskell.

    Again, thank you ^_^

  6. Carlos says :

    i love you ayumilove….

    you re pretty intelligent to do all this work with haskell coding….could you out some new haskell tutorial videos… i am a student of engineering in systems…i see so much of haskell lenguaje..and its so hard for me to do it all alone…i hope you bring me out some help—i cant do it all by myself…i got a question: how do i do this?

    a) Given a chain, the letters spend(pass) in position couple(par) to capital letter, and those of odd position to small letter.

    i hope so much you could bring out some help….kisses, take care and your blog its wonderfull!!!!!


    cac_666@hotmail.com answer me PLEASE!!!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: