Skip to content
HomeVideosBooksBlogs
AllTop postsTopics
Podcasts
HistoryListsWatch laterLiked videosFollowing

The videos, books, blogs and podcasts Hacker News keeps recommending, all in one place.

VideosBooksBlogsPodcastsAboutPrivacySettings

Data from Hacker News, HackerTube, HackerBooks, HackerBlogs and Open Library. Credits · Not affiliated with Y Combinator.

HomeVideosBooksBlogsPodcasts
Ctrl K
    V

    Valued Lessons

    valuedlessons.com · Personal blog · on HN since 2008

    A programming blog from 2008 with Python tutorials on monads, parsing, reactive programming and memory usage.

    Visit blogHN submissions
    Languages & CompilersProgramming
    What HN says

    HN commenters recommend its monads-in-Python post as a favorite monad tutorial because it avoids Haskell, and point to the Pysec parsing follow-up.

    Stats for nerds
    19HN people shared it
    10linked in comments
    182story points
    Jul 2017last shared
    2009people per year2017

    Top posts on HN

    1. 1
      Monads in Python (with nice syntax)
      11 people · 141 points · first shared 2008 · 48 comments on HN
    2. 2
      Python memory usage of common types
      2 people · 32 points · first shared 2009 · 3 comments on HN
    3. 3
      Garlic Programmers for Silver Code? How your code base affects productivity
      1 person · 6 points · first shared 2008 · 1 comments on HN
    4. 4
      Simple Reactive Programming with Python
      1 person · 2 points · first shared 2012 · Discussion on HN
    5. 5
      List Monad in Ruby and Python
      1 person · 1 points · first shared 2010 · Discussion on HN
    6. 6
      Pysec monadic combinatoric parsing in
      2 people · first shared 2010
    7. 7
      Sql is now turing complete
      1 person · first shared 2015
    8. 8
      Introducing pyrec cure to bane of init
      1 person · first shared 2011

    What HN people wrote when they linked it

    • jmillikinFeb 2010

      C and Java can't represent monads at all, since they don't support closures.

      C# and Python can, sort of, but their syntax and object-oriented semantics make it somewhat difficult. I don't know C# well, and Python needs a lot of magic[1] to get reasonable-looking code.

      Here's a Python example. It's not a direct translation, but is close enough that you should be able to figure out the original. I've included the Haskell code in comments.

      import abc

      # class Monad m where
      # build :: a -> m a
      # bind :: m a -> (a -> m b) -> m b
      class Monad (metaclass = abc.ABCMeta):
      @classmethod
      def build (cls, x):
      raise NotImplementedError

      def bind (self, f):
      raise NotImplementedError

      # data Maybe a = Just a | Nothing
      # deriving (Show)
      class Maybe (Monad):
      def __init__ (self, x):
      self.__x = x

      def __repr__ (self):
      if self is Nothing:
      return "Nothing"
      return ("Just %r" % self.__x)

      # instance Monad Maybe where
      # build x = Just x
      #
      # bind Nothing _ = Nothing
      # bind (Just x) f = f x
      @classmethod
      def build (cls, x):
      return Just (x)

      def bind (self, f):
      if self is Nothing:
      return Nothing
      return f (self.__x)

      def Just (x):
      return Maybe (x)

      Nothing = Maybe (None)

      # clamp limit x = if x > limit then Nothing else Just x
      def clamp (limit, x):
      if x > limit:
      return Nothing
      return Just (x)

      # multiclamp2 lim1 lim2 x = bind
      # (clamp lim1 x)
      # (\x'…

    • fizixerJan 2016

      > Do I need to know Haskell? Yes.

      This is enough for me to reject this blogpost.

      No you don't need a specific language to implement any functionality that can be implemented by a turing-complete language.

      I watched Crockford's monad talk [1]. He used javascript. The only problem with that talk is that he spent about 10 seconds or less explaining what a monad is (and the rest of the talk on implementation issues and his own perspective, etc, etc).

      I'm still waiting for a good monad discussion without CT or Haskell. (this [2] and this [3] look promising, both in python)

      [1] https://www.youtube.com/watch?v=b0EF0VTs9Dc

      [2] http://www.valuedlessons.com/2008/01/monads-in-python-with-nice-syntax.html#6799472260664409462

      [3] http://www.dustingetz.com/2012/04/07/dustins-awesome-monad-tutorial-for-humans-in-python.html

    • a3nSep 2015

      "It's a pattern."

      "All useful languages have monads ... nearly impossible to avoid."

      So here's a post on Python (hopefully useful) and monads, it appears to be implementing a pattern, although I don't think I would have ever stumbled across it naturally.

      http://www.valuedlessons.com/2008/01/monads-in-python-with-nice-syntax.html

      And here's a library implementing monads and other stuff:

      https://pypi.python.org/pypi/PyMonad/

      It still looks like I'm going to have to try using them before I can figure out if it's worth trying to use them.

    • codygmanJul 2014

      Monads are useful and unknowingly created in other languages all the time [0].

      If you aren't quite comfortable enough with monads to follow the first link, I found this implementing monads in python tutorial[1] to be a huge help.

      For those that want to play with Monads in Python, check out PyMonad[2].

      0: http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html

      1: http://www.valuedlessons.com/2008/01/monads-in-python-with-nice-syntax.html

      2: https://pypi.python.org/pypi/PyMonad/

    • yablakJul 2017

      A parser combinator may be more powerful? Not sure.

      The python parsec package is really terribly documented, but there's a good example here:

      http://www.valuedlessons.com/2008/02/pysec-monadic-combinatoric-parsing-in.html

      EDIT:

      The name of the package may have changed; it looks like this is the pypi package being documented (if not; i'm confused because pypi's pysec package is something totally different):

      https://pypi.python.org/pypi/parsec

    • pmiller2Nov 2009

      Here is my favorite monad tutorial: http://www.valuedlessons.com/2008/01/monads-in-python-with-nice-syntax.html . The reason I like it is because it uses Python rather than Haskell while pointing out that you can build monads in any language that supports objects or closures.

      Actually, now that I think about it, it seems to me that pythonic monads should really be context managers, so they can be used like:

      with SomeMonad:
      do stuff

    Related

    Oleg Kiselyovokmij.org251 people

    How the OCaml type checker works (2022)

    Oleg Kiselyov
    Personal · last shared 2026
    Jon Sterlingjozefg.bitbucket.org19 people

    Leaving Go

    Jon Sterling
    Personal · last shared 2016
    Bryan O'Sullivanserpentine.com49 people

    Github is making me feel stupid(er)

    Bryan O'Sullivan
    Personal · last shared 2021
    FP Complete Blogfpcomplete.com201 people

    Monads and GATs in Nightly Rust

    FP Complete Blog
    Company · last shared 2025
    Well-Typed Blogwell-typed.com60 people

    Falsify: Hypothesis-Inspired Shrinking for Haskell (2023)

    Well-Typed Blog
    Company · last shared 2026
    Justin Leblog.jle.im36 people

    Typesafe Neural Networks in Haskell with Dependent Types

    Justin Le
    Personal · last shared 2026
    Simon Marlowcommunity.haskell.org/~simonmar17 people

    Parallel and concurrent Haskell, Marlow [[PDF slide deck]]

    Simon Marlow
    Personal · last shared 2017
    Not a Monad Tutorialnotamonadtutorial.com40 people

    Weld: Accelerating numpy, scikit and pandas as much as 100x with Rust and LLVM

    Not a Monad Tutorial
    Publication · last shared 2023