Skip to content

school-Tygo-van-den-Hurk/TUe-2IPH0-Functional-Programming-2025-2026-getting-started

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assignment -1: Getting Started

Follow the steps below to get started with Haskell programming for the assignments. At the end of this assignment you upload proof of a working Haskell development environment to Canvas in the form of a screenshot.

During the assignments, we expect you to work like a software developer and document and test your code. For each assignment, like this one, we have created a Git repository with a Cabal project. Like similar build tools for other programming languages, you use Cabal to generate your documentation, test your code, build your project, and run your application.

  1. Make sure you have installed Git.

  2. You should have installed a Haskell development environment that includes

    when you followed the tutorial 'Set Up Your Haskell Environment'.

  3. If you did not do so before, clone this Gitlab repository. Open a command prompt and run the following commands:

    cd your-2IPH0-directory
    git clone git@gitlab.tue.nl:study-material-2iph0/gettingstarted.git
    cd gettingstarted

    If the git@… URL does not work, try the https variant https://gitlab.tue.nl/study-material-2iph0/gettingstarted.git instead.

Note: Do not clone your repositories into a cloud-managed folder (e.g. OneDrive), a folder structure that contains spaces (' ') or is too long (>128 characters). This will cause problems with the Haskell build tool, especially on Windows machines. I.e. do not do something like 'C:/OneDrive/Documents/Courses/Bachelor/Computer Science/Year 2/Additional/Long/Folder/Structure/That/Does/Not/Make/Sense/gettingstarted'.

  1. Start VSCode. If this is the first time you start VSCode, you will see the Welcome screen:

    VSCode's Welcome screen

    Otherwise, you will likely see the files and directories you have opened last.

  2. Open the directory gettingstarted via menu FileOpen Folder…. This directory is a Cabal project. If you expand the subdirectories src and test, your VSCode window looks like:

    Directory gettingstarted opened in VSCode

  3. Open a terminal in VSCode via menu TerminalNew Terminal. Notice the keyboard shortcut for the next time you want to switch to the terminal. On a wide screen, putting the terminal (1) to the right side of VSCode might be more comfortable. Right-click on the Terminal tab, and select the option Move Panel Right.

    Your VSCode window looks like:

    Terminal opened in VSCode

  4. Run the test suite for this Cabal project by entering the following command in the terminal:

    cabal test
    

    If this is the first time running Cabal in this directory, Cabal has to install some packages.

    The test fails (2).

    Running cabal test for the first time

    If you look in the file explorer (1), you see that Cabal has created the directory dist-newstyle. You can ignore this directory.

    Note On Windows you might get some obscure error like:

    ...
    realgcc.exe: error: C:\long\path\gettingstarted\dist-newstyle\build\x86_64-windows\ghc-8.10.7\gettingstarted-0.0.0.1\t\gettingstarted-test\build\gettingstarted-test\gettingstarted-test-tmp\Main.o: No such file or directory
    `gcc.exe' failed in phase `Linker'. (Exit code: 1)
    ...
    

    The likely cause of this error is too long a path to this repository. To resolve this, move the repository to C:\ and try again.

  5. Fix the function sayHelloTo in the module Hello in the file src/Hello.hs. Double-click on Hello.hs in the file explorer (1). VSCode opens the file in the editor pane (2).

    While fixing this module, you might want to explore what the function sayHelloTo is doing. You can load and run functions from modules in the REPL (3). Switch to the terminal (use the keyboard shortcut) and run the command:

    cabal repl
    

    You will see the following output in the terminal:

    Running the Haskell REPL in the VSCode terminal

    You see that Cabal has loaded the library gettingstarted-0.1.0.0 in GHCi. This library is defined in the file gettingstarted.cabal and contains only the src/Hello.hs module. In other words, the src/Hello.hs module is loaded automatically in GHCi.

    When you enter sayHelloTo "the teacher" at this GHCi prompt, it responds with:

    "the teacher"
    

    This means that at the moment sayHelloTo echos the argument you supply it. However, it should have responded with Hello, the teacher!.

  6. Change the function sayHelloTo in src/Hello.hs to fix this issue. If you want to try your changes, save the file, switch to the terminal, and enter :reload (or :r) at the GHCi prompt. This will reload the module and you can try the updated version in the REPL.

  7. When you think you fixed sayHelloTo, save the file src/Hello.hs, switch to the terminal, and quit GHCi by entering :quit (or :q). Now rerun the test suite.

  8. If the test succeeds, make a screenshot of VSCode that shows your solution (3), name, and student ID in the editor (2) and the passing test in the terminal (1). Upload this screenshot to Assignment -1 on Canvas.

    For example, for me, this looks like:

    Proof of a working Haskell development environment

    Of course, I've blurred the actual solution I came up with!

About

This assignment is just to show you have a working haskell environment/setup and can actually make the other assignments.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors