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

• ```concat :: [[a]] -> [a] -- generalized: join :: Monad m => m (m a) -> m a {- if you sub m=[], you'll get: join :: [] ([] a) -> [] a = join :: [[a]] -> [a] :) -} -- dual of join: duplicate :: Comonad w => w a -> w (w a) -- but I'm not well
versed in the area of comonads :p```

• Talking about unfolds, someone from #haskell once wrote a beautiful implementation using a GHC extension here on hpaste.

• Re: parentheses, the ones around the lambda are just the same as in any ordinary expression, for example:

`foo x y = x * (y+x)`

About the language being able to deconstruct lists, that's because Haskell is designed to deconstruct any algebraic data type (ADT).

`-- ADT for a linked list: data List a -- [a] <--> List a = Cons a (List a) -- (:) <--> Cons | Nil -- [] <--> Nil -- ADT for a binary tree: data BTree a = Node (BTree a) (BTree a) | Empty`

And yes, your drop2 function does exactly what you say it does, although you don't need the inner parentheses in the pattern.

• Function application is like search/replace. If we have the following definition:

`add = \x -> (\y -> x+y)`

If we apply the function to e.g. 3, we'll get:

`add 3 = {- replace add by its definition -} (\x -> (\y -> x+y)) 3 = {- now substitiute 3 for x, i.e. function application -}  {- no further substitution possible -}`

Now, if we'll apply this result to e.g. 4, we'll get:

`(\y -> 3+y) 4 = {- function application, sub 4 for y -} 3+4 = {- use the definition of (+) -} 7`

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

• The slides can be found here.

• I don't think it's a good idea if a function would automatically be transformed to a point-free notation by the IDE. Sometimes the point-free version is much harder to read**. Nevertheless, it would be a great optional tool in an IDE.

** Example:

`-- pointful: mult x y z = z*y*x -- pointfree generated by lambdabot's @pl tool: mult = flip (flip . ((*) .) . (*))`

Btw, the pointfree version of this example can be made simpler if you'll use the commutativity of (*). The only problem is that the commutativity property is not garantueed, so a (syntactic) pointfree tool cannot rely on it.

• For those who are interested, the C# zip function Erik talked about (shown below)...

`IEnumerable zip<T,S,R>(IEnumerable<T> xs, IEnumerable<T> ys, Func<T,S,R> f) { //... }`

...also exists in Haskell as zipWith

`zipWith :: (a -> b -> c) -> ([a] -> [b] -> [c])`

...and can be implemented using only two lines of Haskell.

• You can type things like

`3 :: Int`

in Hugs or GHCi and it will work. Hugs and GHCi are interpreters that expect expressions, which they'll gladly evaluate and print.

However, when you type something like

`f :: Int -> Int -> Int`

in Hugs or GHCi, you're asking it to evaluate the expression f and telling the interpreter it has type Int -> Int -> Int. There are several problems with this. First of all, the interpreter does not know what this "f" thing is you're talking about, unless you have defined f in a Haskell script and have loaded that script file. Secondly, if you did define f somewhere, functions themselves cannot be printed to the console.**

** Often the cryptic error thrown by the interpreters is something along the lines of "There is no Show instance for Int->Int->Int".

• Let's mention the M-word in this thread.

```-- from the slides: double x = x + x quadruple x = double (double x) -- Erik's pointfree version of quadruple from the whiteboard: quadruple = double . double -- The version of a Haskell programmer in love with the Reader monad: double
= join (+) quadruple = join (.) double ```