patch applied (haskell-prime-status): add ""Make $ left associative, like application"

Dan Doel dan.doel at gmail.com
Wed Apr 23 17:19:21 EDT 2008


On Wednesday 23 April 2008, Bulat Ziganshin wrote:
> it's not refactoring! it's just adding more features - exception
> handler, progress indicator, memory pool and so on. actually, code
> blocks used as a sort of RAII for Haskell. are you wanna change all
> those ';' when you add new variable to your C++ code?
>
>   bracketCtrlBreak (archiveReadFooter command arcname) (archiveClose.fst) $
> \(archive,footer) -> do bad_crcs <- withList $ \bad_crcs -> do
>       doChunks arcsize sector_size $ \bytes -> do
>         uiWithProgressIndicator command arcsize $ do
> or
>     handleCtrlBreak  (ignoreErrors$ fileRemove arcname_fixed) $ do
>     bracketCtrlBreak (archiveCreateRW arcname_fixed) (archiveClose) $
> \new_archive -> do withJIT (fileOpen =<< originalURL originalName arcname)
> fileClose $ \original' -> do
>
> is just two examples from my code

For what it's worth, both of these examples require no change.

However, with left-associative ($), you're free to change them to (sorry for 
the additional lines, but my mail client breaks at 80 characters. I think 
they're still valid code):


    bracketCtrlBreak $ archiveReadFooter command arcname
                     $ archiveClose.fst
                     $ \(archive,footer) -> do
      bad_crcs <- withList $ \bad_crcs -> do
        doChunks arcsize sector_size $ \bytes -> do
          uiWithProgressIndicator command arcsize $ do

    handleCtrlBreak $ ignoreErrors (fileRemove arcname_fixed) $ do
    bracketCtrlBreak $ archiveCreateRW arcname_fixed $ archiveClosed 
                     $ \new_archive -> do
    withJIT $ fileOpen =<< originalURL originalName arcname $ fileClose
            $ \original' -> do

Or, for a simpler example I discovered earlier, you can write:

    catchError $ do return 1
                    throwError $ strError "foo"
               $ \e -> return 2

Although I'm not sure how much better that is than the alternative:

    do return 1
       throwError $ strError "foo"
    `catchError`
    \e -> return 2

-- Dan


More information about the Haskell-prime mailing list