Posted By: Charles | Nov 26th, 2009 @ 10:48 AM | 52,087 Views | 44 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 9, Interactive Programs, Dr. Meijer will teach us how to make programs in Haskell that are side-effecting: interactive. Haskell programs are pure mathematical functions with no side effects. That said, you want to be able to write Haskell programs that can read input from the keyboard and write output to the screen which are in fact side effects. So, interactive programs have side effects... Interactive programs can be written in Haskell by using types to distinguish pure expressions from impure actions that may involve side effects.

Consider the following:


IO a
The type of actions that return values of type a

IO Char
The type of actions that return a character

IO()
The type of purely side effecting actions that return no result value

Warning: This lecture may contain the use of the term Monad. Do not fear. Everything will be OK. Smiley

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

Get the presentation slides here

Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Rating:
9
0

Until this US Thanksgiving, I never realized that monads and turkey go together so well!  Thank you Erik for your excellent tutorials.  Hopefully the future of code will be more sane from your efforts  =)

exoteric
exoteric
embarassingly sequential

To be sure: once an expression involves IO, is it possible to ever derive a type that is not IO'd from it? I suspect not.

 

Thanks for the palm tree. It's a great place to be lazy, as its recursive structure bends over the ever-changing sea of waves.

You can do that using my all time favorite non-function unsafePerformIO :: IO a -> a. Keep in mind that as the name warns you, it is unsafe, very unsafe.

I'm having a problem downloading or displaying this video. When downloading it gets to 6% and stops.  If I try and display it in the in-line Silverlight player and skip forward to eight minutes or so it has a media failure.  I'm seeing the same problem with many of the PDC videos, e.g (WMV high):

http://microsoftpdc.com/Sessions/FT24

 

...Stefan

In essence, the point of the IO monad is to "tag" values as IO when there's a possibility of state.  Once you enter the dimension of state, you can of course not remove the idea that side effects have occured.  Therefore, it is recommended to keep your code pure.

 

Using do-notation and the monadic functions, it isn't too hard to make working with monads not too difficult, and for some, fun  =)

exoteric
exoteric
embarassingly sequential

Now to examine why anyone would want to soil an otherwise clean language, i.e. the use-cases.

I cannot download or play WMV file.  Download stops at about 8%.

Download of WMV finishes for me after 7.90 MB. Please don't make me download WMV (High) !

I am in New Zealand.

In general downloading this video series has been very slow. It looks like the maximum bandwidth is about 200KBytes/s . Normally I can get 900K - 1.2 MBytes/s from microsoft.

 

Still - it is an extremely interesting series and very worthwhile. Even if it just turns out (for me) to be background to F# and Linq.

-G

Microsoft Communities