Posted By: Charles | Oct 22nd, 2009 @ 11:34 AM | 51,978 Views | 28 Comments

We've kicked off C9 Lectures with a journey into the world of Functional Programming with functional language purist and high priest of the lambda calculus, Dr. Erik Meijer (you can thank Erik for many of the functional constructs that have shown up in languages like C# and VB.NET. When you use LINQ, thank Erik in addition to Anders). 

We will release a new chapter in this series every Thursday.

In Chapter 4, Dr. Meijer teaches us about the art and practice of defining functions. Functions can be defined using conditional expressions and in Haskell conditional expressions must always have an else clause. Functions can also be defined using guarded equations and pattern matching. You will learn about list patterns and integer patterns. Today is also the day that you will learn about lambda expressions and sections.

You should watch these in sequence (or skip around depending on your curent level of knowledge in this domain):

Chapter 1
Chapter 2
Chapter 3

Now, we do have a textbook and you should go buy it: The great Graham Hutton's Programming in Haskell. We worked with the publisher, Cambridge University Press, to get all Niners a 20% discount on the book. Now, you don't need the book to learn a great deal from this lecture series since Graham's website has all the slides and samples from the book as well as answers to the exercises. That said, it's highly recommended reading and you should consider it.

The promotion code is 09HASK and it is vaild on both the Hardback:

9780521871723 and Paperback: 9780521692694. The catalog pages are:

Hardback:

http://www.cambridge.org/us/catalogue/catalogue.asp?isbn=9780521871723 and the paperback is:

http://www.cambridge.org/us/catalogue/catalogue.asp?isbn=9780521692694

Note: This special offer is valid until December 31, 2009

Rating:
16
0

I'm enjoying this series so much and can't wait to see where Erik takes us by the 13th episode! I very much like the 'comp.sci culture and history' asides that Erik provides along with the main course content, keep this up - it both animates and roots the lectures!

I've been waitin for this all day (time difference, you know) -- and it was well worth it. Big Smile

 

I love the “back to school” feeling I get with these lectures. I like Novox have been waiting all day for this. Keep up the good work Smiley

exoteric
exoteric
embarassingly sequential

I love currying and partial application and sectioning just elevates that to a higher level of bliss.

It would be great if this expression type-checked in C#: s.Select(1+).

 

Then about \x -> x vs x |-> x. I must admit the mathematical notation is less noiseful.

In both situations an IDE should automatically transform both symbols into their unicode equivalents.

So even if typing ==, it will be transformed (graphically) to =, possibly colored differently, and remain unambiguous.

 

It's also funny, because when trying to model boolean expressions in Java back in 2002, it became very obvious to use this approach outlined by Erik. Still, not entirely convinced it's superior to the functional approach but indeed it does provide some abstraction over structure: F# has these Active Patterns which may be a solution to that problem, haven't looked into it. Let me try again, forgot the old implementation...

 

It's definitely it's something interesting to ponder.

 

n+k patterns. Not enough data to conclude non-/justification, must search...

 

public abstract class Bool
{
    public abstract Bool Not();
    public abstract Bool And(Bool _);
    public abstract Bool Or(Bool _);
}
public class False : Bool
{
    private False() { }
    public static readonly Bool A = new False();
    public override Bool Not()
    {
        return True.A;
    }
    public override Bool And(Bool _)
    {
        return this;
    }
    public override Bool Or(Bool that)
    {
        return that;
    }
}
public class True : Bool
{
    private True() {}
    public static readonly Bool A = new True();
    public override Bool Not()
    {
        return False.A;
    }
    public override Bool And(Bool that)
    {
        return that;
    }
    public override Bool Or(Bool _)
    {
        return this;
    }
}
public static class Bools
{
    public static Bool Box(this bool x)
    {
        return x ? True.A : False.A;
    }
    public static bool Unbox(this Bool x)
    {
        return x is True; // unsafe : x == True.A; unless we seal
    }
    public static Bool Andy(this Bool a, Bool b)
    {
        return (a.Unbox() && b.Unbox()).Box();
    }
    public static Bool Ory(this Bool a, Bool b)
    {
        return (a.Unbox() || b.Unbox()).Box();
    }
}

 

Day.Exit;

There are editors that replace certain Haskell symbols with their unicode equivalents. One example is emacs as shown in this blog post.

Erik, the series is wonderful -- I have been watching every chapter with much interest.

Fantastic job. Thanks so much and I am really looking forward to watching all the remaining chapters!

Radu

exoteric
exoteric
embarassingly sequential

Ok that does it. Time to install Emacs.

 

...It's a fun idea to use a Lisp-based editor to "type" Haskell

chudq
chudq
Life is beautiful, and sharing is wonderful!

There is not much actual hands-on programming in this show.  For example, for a simple function of abs, I could not figure out how to define it in Hugs. I notice that my Hugs has abs predefined already for using. Then I tried to type in:

 

    abs1 n = n, n >=0

 

I got error and could not coninue the next branch. I guess I have to edit my script and load it. How?

Microsoft Communities