Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, it's pattern matching (it's a bit warty because that's the only case I can think of where the pattern matching part doesn't look like the way you build the data structure).

Normal pattern matching:

   -- a Foo record, with a data constructor Foo and a single field
   data Foo = Foo { bar :: String }

   -- takes an instance of Foo, returns "prefix:" + the value of the bar field
   prefixBarInFoo :: Foo -> String
   -- Pattern matches on Foo, tells Haskell to bind 'valueOfBar' to the 'bar' field of the instance of Foo
  prefixBarInFoo (Foo valueOfBar) = "prefix:" ++ valueOfBar
List pattern matching:

    myList = [1,2,3,4,5]

    addOne :: [Integer] -> [Integer]
    addOne [] = []
    -- when called with 'myList', binds x to 1 and xs to [2,3,4,5] (the rest of the list)
    addOne (x:xs) = (x+1) : (addOne xs)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: