Code Examples
FP
On this page we place some Haskell Modules that have been referred to in the cours:
The calendar program
The file
Calendar.hs contains the full code of the calendar program.
An extremely simplistic Prolog-like interpreter
The package
nanoprolog contains a simplistic Prolog interpreter which you can study. It is a bit more involved than the one dealt with in the lecture notes; it provides a bit more information about the whole backtracking process. You can install it as follows:
cabal install nanoprolog
If you unpack the
attached file you can run it as:
nano-prologdyn-81-18:NanoProlog doaitse$ ls
LICENSE README royals.pro
Makefile Setup.hs src
NanoProlog.cabal dist tc.pro
dyn-81-18:NanoProlog doaitse$ cd src
dyn-81-18:src doaitse$ ghci Main.hs
GHCi, version 7.0.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 3] Compiling Language.Prolog.NanoProlog.NanoProlog ( Language/Prolog/NanoProlog/NanoProlog.hs, interpreted )
[2 of 3] Compiling Language.Prolog.NanoProlog.Interpreter ( Language/Prolog/NanoProlog/Interpreter.hs, interpreted )
[3 of 3] Compiling Main ( Main.hs, interpreted )
Ok, modules loaded: Language.Prolog.NanoProlog.NanoProlog, Language.Prolog.NanoProlog.Interpreter, Main.
*Main> main
Loading package array-0.3.0.2 ... linking ... done.
Loading package bytestring-0.9.1.10 ... linking ... done.
Loading package containers-0.4.0.0 ... linking ... done.
Loading package filepath-1.2.0.0 ... linking ... done.
Loading package old-locale-1.0.0.2 ... linking ... done.
Loading package old-time-1.0.0.6 ... linking ... done.
Loading package unix-2.4.2.0 ... linking ... done.
Loading package directory-1.1.0.0 ... linking ... done.
Loading package process-1.0.1.5 ... linking ... done.
Loading package time-1.2.0.3 ... linking ... done.
Loading package random-1.0.0.3 ... linking ... done.
Loading package haskell98-1.1.0.1 ... linking ... done.
Loading package ListLike-3.1.2 ... linking ... done.
Loading package uu-parsinglib-2.7.1.1 ... linking ... done.
File with rules?
../tc.pro
wellTyped(map, ((A) -> B) -> ([A]) -> [B]).
wellTyped(foldr, ((A) -> (B) -> B) -> (B) -> ([A]) -> B).
wellTyped(ap(F, V), A):-wellTyped(F, (B) -> A), wellTyped(V, B).
goal?
wellTyped(ap(map,map),X)
0 wellTyped(ap(map, map), ([(A0.2) -> B0.2]) -> [([A0.2]) -> [B0.2]]):-wellTyped(map, (((A0.2) -> B0.2) -> ([A0.2]) -> [B0.2]) -> ([(A0.2) -> B0.2]) -> [([A0.2]) -> [B0.2]]), wellTyped(map, ((A0.2) -> B0.2) -> ([A0.2]) -> [B0.2]).
0.1 wellTyped(map, (((A0.2) -> B0.2) -> ([A0.2]) -> [B0.2]) -> ([(A0.2) -> B0.2]) -> [([A0.2]) -> [B0.2]]).
0.2 wellTyped(map, ((A0.2) -> B0.2) -> ([A0.2]) -> [B0.2]).
substitution: X <- ([(A0.2) -> B0.2]) -> [([A0.2]) -> [B0.2]]
goal?
quit
*Main>