I grow under the sun. When I am not writing code, I am either drinking wine or drinking tea (with these little cups). Cheese is my bread and tracking everything in Emacs is my cheese.
P.S. d12frosted means dice with 12 sides from the Chessex™ frosted series. I used to play. Just a little bit.
When we write libraries for others (including ourselves) to use we often require some preconditions to be met. Sometimes we just make them implicit (in the form of folklore, passed from developer to developer during post mortem ritual). In other cases we encode the possibility of failure due to unsatisfied preconditions.
Is this is the only thing we can do? Definitely no! Is it the best thing we can do? Depends on the situation.
This article is part of the readings series where I take one topic and share links to related articles and papers. This time our focus is precondition encoding.
They say functional programming has many essences and the composition is one of them. Thanks to the wonderful dot operator, we know how to compose functions like
a -> b and
b -> c to get a function
a -> c. But in some cases functions are not that simple and it becomes tricky to compose them nicely.
It would be lovely to express it in a more declarative way by abstracting away function application and result combination.
Apart from implementing combinators for predicate composition, we want to avoid any runtime penalty from using abstractions. In this article we are going to implement the following functions and investigate how far we can go with abstractions until performance degrades. Or maybe it won’t degrade. Who knows?
It’s hard (though possible) to imagine a script that doesn’t access environment variables. In Haskell ecosystem there is a good built-in module System.Environment that does the job, but it has several drawbacks. First of all, it uses
String data type as input and as an output. And secondly, it lives in
IO. Both of these drawbacks are not that critical, but calling all these
liftIO in every program drives me nuts. So several years ago (somewhere in 2016) I decided to write a simple library that wraps it for me.
I’ve been using this library for a long time and today I uploaded it to Hackage. While it’s really small, I still think that some of you might find it useful, because it has nice features that original
System.Environment doesn’t have. Let’s take a look!
Maybe I did something really wrong in my life, because I constantly run into Cabal Hell. That feeling of powerlessness is refreshing, though depressing. And I hate it the most when I just need to install an executable from Hackage, like
But hey, we are software engineers after all. So I decided to write a little helper script to avoid world destruction and get desired executable in my
Important note. In the last few years Haskell community did a great job in order to fight the Cabal Hell. And thanks to Stack and Nix-style Local Builds my solution is no longer required. I keep it just for historical reference (and to keep my blog relatively busy).