Merry Christmas, great effort once again. Channel9 is my one stop destination to listen and watch this and all the other videos on C++/STL/Haskell and so on and so forth. Thank you Mr. Stephan T. Lavavej, Charles and all the other nice people at Channel9.

all' :: (a -> Bool) -> [a] -> Bool --all' p as = foldr (\x xs -> x && xs) True $ foldr (\x xs -> if p x then True : xs else False : xs) [True] as all' p xs = foldr (\x xs -> p x && xs) True xs

any' :: (a -> Bool) -> [a] -> Bool any' p xs = foldr (\x xs -> p x || xs) False xs

takewhile' :: (a -> Bool) -> [a] -> [a] takewhile' p xs = foldr (\x xs -> if p x then x : xs else xs) [] xs

dropwhile' :: (a -> Bool) -> [a] -> [a] dropwhile' p xs = foldr (\x xs -> if not (p x) then x : xs else xs) [] xs

## Comments

## Interview with Jennifer Marsman

Nice talk, picked up couple of interesting things about data analysis.

## Modern Methods for Texture Compression

Interesting video; watched it twice, thanks.

## Stephan T. Lavavej - Core C++, 7 of n

Merry Christmas, great effort once again. Channel9 is my one stop destination to listen and watch this and all the other videos on C++/STL/Haskell and so on and so forth. Thank you Mr. Stephan T. Lavavej, Charles and all the other nice people at Channel9.

## Ping 161: Scroogled, Xbox sales, Windows Store wins, IE 10 trolls

Ping is nice show, I watch it almost regularly. Keep on doing this nice show. Kudos to people at Ping.

## WHOIS: Danah Boyd, MSR Social Scientist

"Work to learn from each other."I think this is a good advice for the parents and their children(eager to socialize online).

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 7 of 13

length' = sum . map(\_ -> 1)

length'' = (foldr (\x xs -> x + xs) 0) . (foldr (\_ xs -> [1] ++ xs) [])

all' :: (a -> Bool) -> [a] -> Bool

--all' p as = foldr (\x xs -> x && xs) True $ foldr (\x xs -> if p x then True : xs else False : xs) [True] as

all' p xs = foldr (\x xs -> p x && xs) True xs

any' :: (a -> Bool) -> [a] -> Bool

any' p xs = foldr (\x xs -> p x || xs) False xs

takewhile' :: (a -> Bool) -> [a] -> [a]

takewhile' p xs = foldr (\x xs -> if p x then x : xs else xs) [] xs

dropwhile' :: (a -> Bool) -> [a] -> [a]

dropwhile' p xs = foldr (\x xs -> if not (p x) then x : xs else xs) [] xs

Sohail Qayum Malik

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 7 of 13

Hey,

map :: (a -> b) -> [a] -> [b]

map f [] = []

map f (x:xs) = f x : Main.map f xs

map' :: (a -> b) -> [a] -> [b]

map' f [] = []

map' f xs = Main.foldr (\x xs -> f x : xs) [] xs

filter :: (a -> Bool) -> [a] -> [a]

filter f [] = []

filter f (x:xs) | f x = x : Main.filter f xs

| otherwise = Main.filter f xs

filter' :: (a -> Bool) -> [a] -> [a]

filter' f [] = []

filter' f xs = Main.foldr (\x xs -> if f x then x : xs else xs) [] xs

-- Need Integral class, since method div is provided there

even :: Integral a => a -> Bool

even a = if ((a `div` 2)*2) == a then True else False

foldr :: (a -> b -> b) -> b -> [a] -> b

foldr f v [] = v

foldr f v (x:xs) = f x (Main.foldr f v xs)

Sohail Qayum Malik

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 6 of 13

Finally got some time and went through this lecture too...

(!!) :: [a] -> Int -> a

(a:as) !! 0 = a

(a:as) !! (n + 1) = as Main.!! n

(++) :: [a] -> [a] -> [a]

[] ++ [] = []

as ++ [] = as

[] ++ bs = bs

(a:as) ++ (bs) = a : (Main.++) as bs

(&&) :: Bool -> Bool -> Bool

True && True = True

_ && _ = False

length :: Num a => [a] -> Int

length [] = 0

length [x] = 1

length (a:as) = 1 + Main.length as

take :: Num a => Int -> [a] -> [a]

take 0 _ = []

take _ [] = []

take (n + 1) (a:as) = a : Main.take n as

drop :: Num a => Int -> [a] -> [a]

drop 0 as = as

drop _ [] = []

drop (n + 1) (a:as) = Main.drop n as

qsort :: Ord a => [a] -> [a]

qsort [] = []

qsort [a] = [a]

qsort (a:as) = qsort smaller Main.++ [a] Main.++ qsort greater

where

smaller = [x | x <- as, x <= a]

greater = [x | x <- as, a < x]

and :: [Bool] -> Bool

and [] = True

and (a:as) = a Main.&& Main.and as

concat :: [[a]] -> [a]

concat [] = []

concat (a:as) = a Main.++ Main.concat as

replicate :: Int -> a -> [a]

replicate 0 a = []

replicate (n + 1) a = a : Main.replicate n a

elem :: Eq a => [a] -> a -> Bool

elem [] _ = False

elem (a:as) s = if a == s then True else Main.elem as s

merge :: [Int] -> [Int] -> [Int]

merge [] [] = []

merge [] bs = bs

merge as [] = as

merge as bs = qsort $ as Main.++ bs

msort :: [Int] -> [Int]

msort [] = []

msort [a] = [a]

msort as = merge (msort $ Main.take n as) (msort $ Main.drop n as)

where

n = Main.length as `div` 2

Sohail Qayum Malik.

## A Conversation with Jaron Lanier

Nice conversation, really inspirational. I've included this talk in the list of few talks, I often hear.

Thank you.

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 5 of 13

Hey, late as usual

module Main( main, Main.sum, Main.zip ) where

main = do

print $ pyths 5

print $ perfects 500

-- print $ Main.zip [4,5,6,7] [1,2,3]

-- print $ Prelude.zip [4,5,6,7] [1,2,3]

-- print $ Main.zip [1,2,3] [4,5,6,7]

-- print $ Prelude.zip [1,2,3] [4,5,6,7]

pyths :: Int -> [(Int, Int, Int)]

pyths = \n -> [(x, y, n) | x <- [1..n], y <- [1..n], (x*x + y*y) == n*n]

perfects :: Int -> [Int]

perfects n = [x | x <- [1..n], Main.sum (factors x) == x]

factors :: Int -> [Int]

factors = \n -> [x | x <- [1..n], x < n && n `mod` x == 0]

sum :: [Int] -> Int

sum [] = 0

sum (a:as) = a + Main.sum as

zip :: [Int] -> [Int] -> [(Int, Int)]

zip as bs = dropper (pairs as bs) (length bs)

pairs :: [Int] -> [Int] -> [(Int, Int)]

pairs as bs = [(x,y) | x <- as, y <- bs]

dropper :: [(Int,Int)] -> Int -> [(Int,Int)]

dropper [] _ = []

dropper (a:as) n = [a] ++ dropper (drop n as) n

Sohail Qayum Malik

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 4 of 13

Very late to the class... again

my shot at the homework. Incomplete, of course.

--Case of dynamic dispatch...

class Bool {

public:

virtual Bool* operator!(void) = 0;

virtual Bool* operator&&(Bool&) = 0;

virtual Bool* operator||(Bool&) = 0;

};

class True : public Bool {

Bool* operator!(void);

Bool* operator&&(Bool& ref) {

return &ref;

}

Bool* operator||(Bool& _) {

return new True();

}

};

class False : public Bool {

Bool* operator!(void);

Bool* operator&&(Bool& _) {

return new False();

}

Bool* operator||(Bool& ref) {

return &ref;

}

};

Bool* True::operator!(void) {

return new False();

}

Bool* False::operator!(void) {

return new True();

}

int main(void) {

class Bool *Bt = new True();

class Bool *Bf = new False();

*Bt&&*Bf;

*Bf&&*Bt;

*Bf||*Bt;

!*Bf;

return 0;

}

--Case of double dispatch...

#include <iostream>

using namespace::std;

class Bool {

public:

virtual Bool* AND(Bool&) = 0;

// TF is for true or false

virtual Bool* TF(void) = 0;

};

class True : public Bool {

Bool* TF(void) {

cout<<"True"<<endl;

return new True();

}

Bool* AND(Bool& ref) {

return ref.TF();

}

};

class False : public Bool {

Bool* TF(void) {

cout<<"False"<<endl;

return new False();

}

Bool* AND(Bool&) {

return TF();

}

};

int main(void) {

Bool *Bt = new True();

Bool *Bf = new False();

Bt->AND(*Bf);

Bf->AND(*Bt);

Bt->AND(*Bt);

return 0;

}

Sohail Qayum Malik

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals, Chapter 1 of 13

Very late to the class.

My solution to the Home work ...

//Find x(member of xs), such that the x is central value

void sort(int *array, int size) {

int count, lcount = 0, mcount = 0;

//To hold the smaller xs(than x)

int less[size - 1];

//To hold the larger xs(than x)

int more[size - 1];

for(count = 1; count < size; count++) {

//array[0] is the x

if(array[0] > array[count]) {

//The xs smaller than x

less[lcount] = array[count];

lcount++;

}

else if(array[0] <= array[count]) {

//The xs larger than x

more[mcount] = array[count];

mcount++;

}

}

//Put the x in the middle of the array

array[lcount] = array[0];

if(lcount)

for(count = 0; count < lcount; count++)

array[count] = less[count];

if(mcount)

for(count = 0; count < mcount; count++)

*(array + lcount + 1 + count) = more[count];

if(lcount > 1)

sort(array, lcount);

if(mcount > 1)

//array[lcount] is x

sort((array + lcount + 1), mcount);

}

Sohail Qayum Malik.