Flowcharting functional programming languages

Posted by Sadface on Stack Overflow See other posts from Stack Overflow or by Sadface
Published on 2010-05-03T14:21:54Z Indexed on 2010/05/03 14:38 UTC
Read the original article Hit count: 173

Flowcharting. This ancient old practice that's been in use for over 1000 years now, being forced upon us poor students, without any usefulness (or so do I think). It might work well with imperative, sequentially running languages, but what about my beloved functional programming?

Sadly, I'm forced to create a flow chart for my programm (that is written in Haskell).

I imagine it being easy for something like this:

main :: IO ()
main = do
   someInput <- getLine
   let upped = map toUpper someInput
   putStrLn upped

Which is just 3 sequenced steps, fetching data, uppercasing it, outputting it.

Things look worse this time:

main :: IO ()
main = do
   someInput <- fmap toUpper getLine
   putStrLn someInput

Or like this:

main :: IO ()
main = interact (map toUpper)

Okay, that was IO, you can handle that like an imperative language. What about pure functions?

An actual example:

onlyMatching :: String -> [FilePath] -> [FilePath]
onlyMatching ext = filter f
   where f name = lower ('.' : ext) == (lower . takeExtension $ name)
         lower  = map toLower

How would you flowchart that last one?

© Stack Overflow or respective owner

Related posts about haskell

Related posts about functional-programming