Entries:
Posts:

Something went wrong getting user information from Channel 9

Latest Achievement:

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Something went wrong getting the Visual Studio Achievements

• I think you're missing a great opportunity here. Please ask questions about all the thing that Erik is presenting and you don't understand. I bet you would get a lot of help in the forum. That would help a lot of people that might be having the same issues as you. Also it would give Erik an inside of what concepts are difficult to grasp and help him to better present future chapters.

Another think hat you can do is read the chapter of the book that Erick is going to present in advance. That way you know what's going to be covered. If you don't have the book, the slides are here: http://www.cs.nott.ac.uk/~gmh/book.html#slides.

I hope this helps.

• Exelent! I was looking forward to the next lecture.

• Thanks exoteric. My original solution for init' didn't use composition until I saw the lecture and Erik started talking about function composition (yes, I did the exercises from the book before the lecture ). I'm not sure if good at this point of the lecture to introduce pointfree style. But how am I to say

This was my original solution:

`init’ xs = reverse (tail (reverse xs))`

Which I think people not familiar with Haskell would understand better than

`init’ = reverse . tail . reverse`

I say this, because it took me a while to understand what was going on with the second definition and why the parameter was implicit.

• I think you're being too harsh on F#. F# is an excellent bridge for people that want to learn functional programming. I has all the familiar things that an imperative programmer expects like mutable variables, the “for” loop, objects, Visual Studio support. But once you let go the training wheels, you have access to all the benefits of a functional language.

• Here are my solutions for #2, #3,#4,#5.

#2

n = a `div` length xs
where
a = 10
xs = [1 .. 5]

#3
last' = head . reverse

#4 (Using recursion)

last'' [x] = x
last'' (x:y:xs) = last'' (y:xs)

#5

init' = reverse . tail . reverse

init'' xs = take (length xs - 1) xs

Nice lecture. I really appreciate all the effort. I think we’re on the verge of a paradigm shift. Functional programming is entering the mainstream, like OOP did in the 90’s. I think learning functional programming makes you a better developer on other languages; in particular C# where some many concepts are taken from FP. Now is the moment to make the effort and learn it.

• I know the homework was on VB or C#, but this is a lecture on functional programming. So here  is the homework on F# (I tried to make it as close to the Haskell solution as possible):

//Not recomended if the list is big. Lists on F# are not lazy. ys and zs would be computed on the spot.

//Also, the last statement would blow the stack if the list is too big.

let rec QS = function
| [] -> []
| x::xs ->
let ys = xs |> List.filter((>=) x)
let zs = xs |> List.filter((<) x)
QS ys @ [x] @ QS zs

//Using F# sequences. The equivalent of Haskell lists
let rec QSLazy = function
| Empty -> Seq.empty
| Seq (x,xs) ->
let ys = xs |> Seq.filter((>=) x)
let zs = xs |> Seq.filter((<) x)
Seq.append (QSLazy ys) (Seq.append (seq {yield x}) (QSLazy zs))

//Active Pattern to make pattern matching over F# sequences. Needed to make it look more like the haskell solution
and (|Empty|Seq|) xs =
if xs |> Seq.isEmpty then
Empty
else
let x = xs |> Seq.hd
let xs = xs |> Seq.skip 1 |> Seq.cache
Seq (x,xs)

Nice lecture. I'm looking forward to the next one.