[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Monads in Lua
- From: Fabien <fleutot+lua@...>
- Date: Sat, 13 Mar 2010 14:27:14 +0100
Some reasons not to do it:
- Advanced monad usages are hard to get right without static type checking;
- Simple monad usages won't bring you much, in a language which doesn't miss essential things such as side effects, and doesn't encourage super-formal approaches;
- Although Lua has the required functional programming primitives, it stays an imperative language at heart: it's entirely built around tables, which are mutable (as opposed to most Lisps, which are built around non-mutable linked lists). So although you can express functional idioms in Lua, they rarely fill idiomatic, among other because they have to integrate side-effect-full std libs, and side-effect-full user code (which the languages encourages to write).
So, you can transcribe monad examples in Lua, but it probably won't demonstrate anything interesting, won't be good Lua code, and won't constitute a useful library.
In a Lua-like language, services rendered by "useful monads" (list monad, parser combinators...) are better served by libraries which don't make monads explicit IMO: monad usage without dedicated syntax support looks terribly messy ,and doesn't integrate well with the rest of the language. If it doesn't sound obvious, try to write a monad transformer in lambda-calculus, then try adding Lua's verbose syntax over it :-)