Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
76 lines (47 sloc) 1.35 KB

Haskell at CARC

Haskell is a strongly typed functional language. In this QuickByte you will learn how to setup Haskell at CARC and create a simple matrix multiplication project using stack.

On Wheeler:

First we will install and load the stack environment:

  1. module load anaconda

  2. conda create -n haskell stack

  3. source activate haskell

Now create a new stack project:

  1. stack new matmul new-template

  2. cd matmul

Edit the main source file with your preferred text editor:

  1. emacs app/Main.hs

The following code creates and multiplies two 4x4 matrices:


module Main where

import Lib
import Data.Matrix

main :: IO ()

m1 = matrix 4 4 $ \(i,j) -> 2*i - j
m2 = matrix 4 4 $ \(i,j) -> 2*i - j

test = multStd m1 m2

main = do
     putStrLn (show test)

Add the dependency on the matrix package to the project:

  1. emacs package.yaml

  2. Add "- matrix" under dependencies in the executables section so it reads:

	dependencies:		
		- matmul
		- matrix

Build your project:

  1. stack build

Run your compiled program:

(haskell) mfricke@wheeler-sn:~/matmul$
.stack-work/install/x86_64-linux/lts-13.17/8.6.4/bin/matmul-exe
┌                 ┐
│ -18 -16 -14 -12 │
│  14   8   2  -4 │
│  46  32  18   4 │
│  78  56  34  12 │
└                 ┘
You can’t perform that action at this time.