[Haskell-cafe] Can I write this function without doing the action on a different line?
karl at karlv.net
Sun Apr 6 07:15:05 UTC 2014
On Sat, Apr 5, 2014, at 11:31 PM, Matt Joiner wrote:
1. packageBase <- do
2. curDir <- getCurrentDirectory
return . last . splitDirectories . normalise . joinPath $ curDir:ma
Sure. The most obvious transformation to me would have these three
1. The right argument of (:) isn't coming from a monadic action, so you
can extract it as a section and move it to your big long chain of
return . last . splitDirectories . normalise . joinPath . (:
maybeToList package) $ curDir
2. Get rid of the binding of curDir:
getCurrentDirectory >>= return . last . splitDirectories . normalise .
joinPath . (: maybeToList package)
3. Notice that the right argument of (>>=) really isn't using your
monad, so you could use fmap or (<$>) (assuming this is a well-behaved
monad which also has a Functor instance):
last . splitDirectories . normalise . joinPath . (: maybeToList
package) <$> getCurrentDirectory
Fair warning: I'm tired and not type-checking this. But it looks right
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe