Advanced Haskell Features - Lecture Slides | CSSE 490, Study notes of Computer Science

Material Type: Notes; Class: Pattern Recog Using Hid Markov; Subject: Computer Sci & Software Engr; University: Rose-Hulman Institute of Technology; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-r7o
koofers-user-r7o 🇺🇸

1

(1)

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ADVANCED HASKELL
FEATURES
Curt Clifton
Rose-Hulman Institute of Technology
Please SVN Update your HaskellInClass folder,
then open Trees.hs
pf3
pf4
pf5

Partial preview of the text

Download Advanced Haskell Features - Lecture Slides | CSSE 490 and more Study notes Computer Science in PDF only on Docsity!

ADVANCED HASKELL

FEATURES

Curt Clifton Rose-Hulman Institute of Technology

Please SVN Update your HaskellInClass folder,

then open Trees.hs

ADVANCED HASKELL

FEATURES

Modules Pattern matching on data types Guards Testing Instance declarations Infix operators

PATTERN MATCHING AND

GUARDS

data Pair a b = Pair a b twins :: Eq a => Pair a a -> String twins (Pair x y) | x == y = “yep” | otherwise = “nope” Matches a pair and binds x and y Guards work like case but use values instead of patterns Q

TESTING

See sample code for testing depth

INFIX OPERATORS

Surrounding binary function names with backticks lets us use them as infix operators: Hugs> 4 div 2 2 Surround infix operators with parentheses lets us declare their types: (<~) :: BinaryTree a -> BinaryTree a -> BinaryTree a _ <~ ExtNode = error "Can’t attach tree to ext. node" Q