Trying to Learn Haskell
Learning Haskell
With a fresh Ubuntu 12.12 install on my netbook I decided I would try to learn Haskell. I did some Lisp at university and I wanted to see (again) what all the fuss was about with the functional paradigm and Haskell in particular.
I’ve found loads of tutorials and have started a few of them in parallel with the view that going over the same ground a few times will help me better learn/remember/understand the concepts. Different tutorials cover different things so I should pick up a lot from the early parts of the various tutorials.
My main reason for writing this post was that it took me far too long to find out
after installing ghc
(version 7.4.2 by running sudo apt-get install ghc
) why
some of the tutorial code did not compile so I thought I would post this to
help others searching Google for the answer.
GHC Compilation Errors
I had two specific problems, which I have now solved, it was a simple case of installing the required libraries, but I either missed it in the tutorials or they weren’t explicit enough for a Haskell newbie.
From a Haskell tutorial which shows you how to write a simple picnic planning program. The code starts off with:
import Data.List
import Text.Regex
import System.Random
import Data.Ord
which seems ok, however when compiling the first part of the tutorial:
ghc picnic.hs
, ghc spat out the following:
Could not find module `System.Random'
Use -v to see a list of the files searched for.
I moved on to try another Haskell tutorial which tried to create a simple parser which used:
module Main where
import System.Environment
import Text.ParserCombinators.Parsec hiding (spaces)
and gave the following error:
Could not find module `Text.ParserCombinators.Parsec'
Perhaps you meant
Text.ParserCombinators.ReadPrec (from base)
Text.ParserCombinators.ReadP (from base)
Use -v to see a list of the files searched for.
To fix these errors, after some research, I did the following:
sudo apt-get install cabal-install
cabal install random
cabal install parsec
as well as the following to cope with the Text.regex
:
cabal install regex-compat
Now the programs compile and as I learn more I’m sure I will be installing more libraries.