The Magic Dot
So, reading about functors the other day, I noticed something interesting. Specifically, I noticed that in the case of functions,
is equivalent to the composition operation. I think
is possibly the coolest function in all of Haskell, so it annoys me when it requires six characters just to use it as an infix operator.
So I present what is, character-for-character, the coolest Haskell trick I have seen so far:
import Prelude hiding ((.)) import Control.Monad.Instances a . b = a `fmap` b infixr 9 .
And now, all sorts of fun little tricks are possible, like replacing
with
, and replacing
with
And of course, the same function composition magic still works like always. Maybe it's just me, but something this simple, elegant, and fun to use just makes me happy inside.
But finally, I have to ask: is there any way of specifically declaring that a module *replaces* the standard Prelude (or even better, individual elements of it)? It would be really nice to just type
and not have to also bother with adding
Useful Shell Trick
Sometimes, when doing a bunch of data munging in the shell, I want to pass the contents of a file through a shell pipeline, and then directly out into the file again. Unfortunately, doing this the naive way will obliterate the file's contents.
So a while back, I saw a neat little utility called "sponge" which simply buffered data until it ended, and then output it. While useful, this wasn't a standard Unix tool, so I couldn't very well rely on having it available.
Well today, after literally minutes of searching, I have found a command that seems to work just as well:
It outputs all lines in the input, beginning with line zero. Due, I suppose, to the way tail is implemented, it buffers all input before outputting anything.
Not exactly groundbreaking or anything, but a useful little trick to know when playing around in the shell.












