Maybe type is made an instance of the
Applicative type class as follows:
instance Applicative Maybe where pure = Just Nothing <*> _ = Nothing (Just f) <*> something = fmap f something
When working with lists in Haskell, occasionally there’s a need to perform index based operations, such as adding an element at a particular index. As a Haskell newbie, using
foldr is not the first idea that comes to mind when indices are involved. However, there is a general pattern that can be applied when using folds for index-based list operations.
Patrick McKenzie wrote an excellent post about compensation and salary transparency. The entire post is really informative, but for me, this passage is a true gem. Every word here is absolutely true:Read more…
A couple of days ago, I finished reading Paul Graham’s book of essays Hackers and Painters: Big Ideas from the Computer Age, and thoroughly enjoyed the book. I had already read a few of these essays on his website, yet I still enjoyed re-reading them. The essays are very insightful, and I plan to re-read several essays & passages periodically.Read more…
A quine is a program that takes no input and outputs its own source code. It has been a while since I last wrote a quine, so I figured I’ll write one in Objective-C. In general, quines follow a fairly simple formula. The program contains a string that includes all the code before the string and all the code after the string. Depending on the programming language, the string might also contain format string (for languages that use format-strings to print to
A lot of people are familiar with the problem of detecting a loop in a linked list. The problem goes as follows: “Given a linked list, what is the algorithm to determine if it has any cycles (loops)?”Read more…
Stern-Brocot tree is a tree data structure whose vertices correspond to the set of non-negative rational numbers. Thus, this tree provides a very elegant way for constructing the set of fractions
n are relatively prime. To construct the tree, the basic idea is to start with two fractions (
1/0) and then repeat the following operation:
Insert (m+m’)/(n+n’) between two adjacent fractions m/n and m’/n'