An introduction to functional programming. Topics include learning how to program in Haskell; IO and purity in software engineering; functional data structures and algorithms; monads and applicative functors; parsing combinators; Domain Specific Languages (DSLs) and DSL construction; advanced type systems; making assurance arguments; testing and debugging.

Prerequisite: EECS 368 or equivalent or consent of instructor.

Office Hours

  • MTF, 1:00 - 1:50, on Zoom.
  • Zoom Etiquette
    • Zoom puts you into a lobby; I’ll let you in as soon as I’ve conmpleted the conversation with the student I’m with.
    • You must use your real name in Zoom.
  • Links

Classes


{-# LANGUAGE GADTs #-}

import Control.Applicative

data Command
  = Eat Food
  | Stash Food
  | Sleep
   deriving Show

data Food = Pie 
          | Cake
   deriving Show

comprehend :: String -> Either String Command
comprehend "eat pie" = return (Eat Pie)
comprehend "sleep"   = return Sleep
comprehend msg       = Left $ "I dont understand " ++ msg

comprehendFood :: String -> Either String Food
comprehendFood "pie" = return Pie
comprehendFood "cake" = return Cake

runParse :: Parse a -> [String] -> Either String (a,[String])
runParse (Parse f) ts = f ts

data Parse a where
 Parse :: ([String] -> Either String (a,[String])) -> Parse a

--instance Functor Parse
--instance Applicative Parse
--instance Alternative Parse
--instance Monad Parse

parseFood :: Parse Food
parseFood = Parse $ \ ts -> case ts of
  ("pie":ss)  -> return (Pie,ss)
  ("cake":ss) -> return (Cake,ss)
  _ -> Left "food shortage"

-- ... :: Parse a -> Parse [a]