Peano goes Maybe

Just for the fun of it, let's represent Nats as Maybies in Haskell.

import Prelude hiding (succ)
-- A strange representation of Nats
newtype Nat = Nat { getNat :: Maybe Nat }
-- Peano zero
zero :: Nat
zero = Nat Nothing
-- Peano successor
succ :: Nat -> Nat
succ = Nat . Just
-- Primitive recursion for addition
add :: Nat -> Nat -> Nat
add x = maybe x (succ . add x) . getNat
-- Convert primitive Int into strange Nat
fromInt :: Int -> Nat
fromInt 0 = Nat Nothing
fromInt x = succ (fromInt (x-1))
-- Convert strange Nat into primitive Int
toInt :: Nat -> Int
toInt = maybe 0 ((+1) . toInt) . getNat
-- Let's test
main = print $ toInt (add (fromInt 20) (fromInt 22))

I wrote this code in response to a student question, whether and, if so, how one could code recursive functions on maybies. This inspired me towards the exam question as to how the above code compares to more straightforward code which would uses an algebraic datatype with Zero and Succ constructors instead of maybies.


An ontological approach to technology documentation

SE talk at Chalmers, Gothenburg, Sweden

An ontological approach to technology documentation

Room 473 / Wed March 1 - 11:00 - 12:00 

Speaker: Ralf Lämmel, University of Koblenz-Landau

Abstract: In this talk, I am going to present an ontological approach to software technology documentation. That is, usage scenarios of a technology (such as an object/relational mapper, a web-application framework, or a model transformation) are captured in terms of the involved entities (e.g., artifacts, languages, abstract processes, programming paradigms, functions, and function applications) and the relationships between them (e.g., membership, conformance, transformation, usage, and reference). I am going to discuss language and tool support for and experiences with developing such technology documentation. In the SoftLang team at Koblenz, we work on the related but broader notion of "linguistic software architecture" or "megamodeling". I will briefly discuss applications of megamodeling other than technology documentation, namely build management and regression testing. More information: http://www.softlang.org/mega

Slidesin preparation


The Haskell Road to Software Language Engineering and Metaprogramming

FP talk at Chalmers, Gothenburg, Sweden

The Haskell Road to Software Language Engineering and Metaprogramming

2017-02-24, 10.00, conference room 8103, Rännvägen 6, Johanneberg.  

Speaker: Ralf Lämmel, University of Koblenz-Landau

In this talk, I would like to sketch my upcoming textbook on software languages http://www.softlang.org/book while putting on the hat of a Haskell programmer. Overall, the book addresses many issues of software language engineering and metaprogramming: internal and external DSLs, object-program representation, parsing, template processing, pretty printing, interpretation, compilation, type checking, software analysis, software transformation, rewriting, attribute grammars, partial evaluation, program generation, abstraction interpretation, concrete object syntax, and a few more. Haskell plays a major role in the book in that Haskell is used for the implementation for all kinds of language processors, even though some other programming languages (Python, Java, and Prolog) and domain-specific languages (e.g., for syntax definition) are leveraged as well. I hope the talk will be interactive and help me to finish the material and possibly give the audience some ideas about FP- and software language-related education and knowledge management.



Software Language Book ready for review and limited access

I am happy to be done with the draft of the software language book. Just sent it off to Springer for the final verdict/review.

Please find the book's frontmatter (including table of contents, preface, and acknowledgment) as well as the first technical chapter ("The notion of software language") online:


If you like to review the draft book or use it already in class room, please get in touch. The draft is sent to Springer and I hope to receive Springer's Ok+input within three months and finalize the book accordingly no later than May 2017. While under review and further scrutiny, I am going to perform self-motivated proof-reading and fine tuning. (There are some obvious dimensions for the final mile: index, exercises, English, formatting, clarity, bibliography.)

I am going to have a sabbatical Mid of February - End of October 2017. I am super-über-motivated to visit a few places, give guest lectures drawn from the book, and discuss use of the book in teaching, and, of course, engage on research along the way. No matter what, there is going to be extensive slide, video, and code material complementing the book by the end of summer.

All the code that's in the book and a lot more is available online anyway:


BTW, the book's repo is megamodel-managed; see here:

Happy New Year

PS: Just received word from Springer regarding schedule:
  • 1-15 January: Identification of reviewers :-)
  • 15 January - 7 April: Reviewing
  • 7 April - 15 May: Revision
  • 15 May - 1 July: Copy editing
  • 1 July - 1 October: Production
  • 23 - 24 October: Outing at SLE 2017 conference