CPSC 312 – Functional and Logic Programming Course Reflection

CPSC 312 – Functional and Logic Programming was an interesting course. This was the first computer science course that required us to learn and be proficient in two drastically different programming languages.

In this term, we learned both Prolog (logical programming) and Haskell (functional programming).  We also coded TicTacToe in both languages for our two projects.

I found Haskell easy to learn as it was similar to other function-based languages like Java. My favorite part was that each function had a type declaration which basically told us what parameters it took. This made things so much easier! For example:

sum :: Num a => [a] -> a
sum takes a list of some type and returns a value of that type.
That type must implement functions of the Sum class (+, *, -, etc)

Another thing I liked was that there were built in functions in Haskell called foldr and foldr which was basically a “for each” function. Example:

Let the function harmonic take one parameter n.

1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/n

harmonic n = foldr (+) 0 [1/i | i <- [1..n]]

THIS WEBSITE WAS A LIFESAVER: http://learnyouahaskell.com/chapters

Prolog on the other hand did not come second nature to me. Prolog code was weird! Basically you have lines of code which are statements and predicates (if statements) that are true. Then you ask prolog queries and it will tell you whether or not it is true or it can give you a result. For example this is prolog code:

foo([],Y,Y).
foo([A|B],C,[A|D]) :- foo(C,B,D).

and the query that you would type into prolog would be: ?- foo([1,3], [9,7,4], A).
result given: A = [1, 9, 3, 7, 4].

The same function but in Haskell:

foo [] y = y

foo (a:b) c = a: foo c b

Brief summary of prolog topics covered in this class (that I can recall):

  • Propositional Definite Clauses
  • Bottom-up proofs(soundness and completeness)
  • Top-down proofs
  • Box model
  • Negation as failure
  • Relations and Datalog
  • Variables
  • Functions
  • is
  • Lists
  • Trees
  • Difference Lists
  • Triples
  • Ontologies
  • Proofs with variables
  • Unification

Haskell topics:

  • Tuples
  • Lists
  • Recursion
  • Lamda
  • List comprehension
  • Folding
  • Call by value
  • Call by name
  • Lazy evaluation
  • Types
  • Classes
  • Data
  • IO
  • Briefly touched on machine learning
  • Abstract data types

Leave A Comment

Your email address will not be published. Required fields are marked *