[Haskell-cafe] develop new Haskell shell?

Brian Hulley brianh at metamilk.com
Thu May 11 18:22:07 EDT 2006


Brian Hulley wrote:
> rename extFrom extTo files = do
>          let candidates = filter (\(_,ext) -> ext==extFrom) (map split
> files)
>          mapM_ (\f@(n,_) -> rename (unsplit f) (unsplit (n, extTo)))
> candidates
>
> %           ls >>= rename "txt" "hs"

I see I've used the same name twice...;-) It should be:

 ren extFrom extTo files = do
          let candidates = filter
                    (\(_,ext) -> ext==extFrom)
                   (map split files)
          mapM_
              (\f@(n,_) ->
                      rename (unsplit f) (unsplit (n, extTo)))
              candidates

 %           ls >>= ren "txt" "hs"

Of course a better choice of primitive commands would give a more powerful 
shell interface eg using:

renif extFrom extTo fileName =
        case split fileName of
             (n, ext) | ext == extFrom -> rename fileName (unsplit (n, 
extTo))
             _ -> return ()

%    ls >>= mapM_ (renif "txt" "hs")

Regards, Brian. 



More information about the Haskell-Cafe mailing list