Blogs

Haskell Links

Submitted by metaperl on Sun, 04/02/2006 - 8:34am.
The body of my personal blog entry is too short. I need at least 10 words. So here they are :)
  1. Haskell type class figure

If haskellers built a web browser...

Submitted by metaperl on Sat, 04/01/2006 - 10:19pm.

It would be very much like Opera... when I use Opera, I feel like I am using something orthogonal to the internet and opposed to right down in it.

Opera goes to great pains to be elegant and correct and will not let down its hair in the name of practicality or speed. It is very beautiful and it would be nice if the internet raised its standards to opera. But that isn't going to happen.

Life is unfortunately more of a slugfest than a ballet dance. More of a play-it-by-the-ear than force-a-conclusion-by-mathematical-induction.

understanding the Haskell implementation of the least divisor function

Submitted by metaperl on Sat, 04/01/2006 - 5:55pm.

Ok, first LD(n) is the least divisor of n. It is a number, p, such
that p*a = n and a > p and p > 1.

So now to express LD(n) as a Haskell function:


ld n = ldf 2 n

Where ldf 2 n means the least divisor of n that is >= 2.

Hopefully it is understood that the Haskell expression of ld(n) is
equivalent to our initial mathematical definition.

Now, something else that is asserted and then proved:

n > 1 and n not prime IMPLIES (LD(n))^2 less than or equal to n

So then the following definition of ldf k n is offered

ld n = ldf 2 n

ldf k n | divides n k = k
        | k^2 > n     = n
        | otherwise   = ldf (k+1) n

But I do not understand why the second guard is true. Clearly it has
to do with "n > 1 and n not prime IMPLIES (LD(n))^2 <= n" but I do not
see how they relate.

HR - proof - state things [ 'tractably' , 'comprehensively']

Submitted by metaperl on Sat, 04/01/2006 - 11:33am.
I am reading p.4 of The Haskell Road and for a long time struggled with one part of a proof on that page. It was his comment about c, a divisor of n. ... there are natural numbers a and b with c = a * b, and also 1 < a and a < c. but then a divides n..." and that is what confused me. He did not directly show how it was true that a divides n just because c was the least divisor of n.

Stating things tractably:

Let's forget about my problem for a second and look at how to state things tractably. It may be true that if n is prime then that means that n is only divisible by 1 and itself. But is that the most algebraic way of stating it? Can you go from that statement you just made to anything useful? Maybe, but let's take a look at this way of stating it: n prime means that only 1 * n = n and nothing else

One other thing. Let's try this same technique for what it means for a to be divisible by b? It means that b * x = a, where x is integral.

Now what have we bought ourselves? Instead of primeness and divisibility being two concepts with no apparent relation, we see them both in terms of what it means for products involving things which are prime and things which are divisible. Both concepts are now expressed as

 E * F 
where E and F vary based on which concept we are talking about.

Why is this useful? Because at one point in my following the proof, I hit this statement: assume c = LD(n) is not prime. In other words "Assume that the least divisor of n is c and it is not prime." Now we reach the second thing:

State all implications

So let's take our statement and explore each isolated fact: First, c is the least divisor of n tell us all of this:
  • c * q = n
  • 1 * n = n
  • c > 1

    And c not prime tells us all of this:

  • 1 * c = c
  • a * b = c, where a != 1

    Now what threw me is when the author of the text said: "Then there are natural numbers a and b with c = a * b, and also 1 < a and a < c. but then a divides n..." and that is what confused me. He did not directly show how it was true that a divides n. But if you look above, we have

     c * q = n
    but also
    a * b = c
    . By substituing
    a * b
    for c, we have
     a * b * q = n
    which means that a divide n.
  • Haskell on Pocket PC?

    Submitted by dokondr on Thu, 03/30/2006 - 6:37am.

    Any ideas on how much work needs to be done for using Haskell on PPC Windows Mobile platform?
    It would be interesting to use PPC as:
    1) Haskell learning tool, so small code snipets could be entered and run directly on hand-held (REPL). How hard is it to port Hugs to PPC for this? Do any other (then Hugs) implementations exist that are easier to port?
    2) Running on PPC Haskell applications cross-compiled on host PC. How much work must be done for GHC to support this?

    3) There are several ways both for porting Haskell to PPC as well as cross-compiling Haskell code. Which one makes more sense to implement and will take less effort:
    a) Porting/compiling to VM byte code (Java, Parrot)?
    b) Porting/compiling to .NET CLR?

    4) And finally, do any projects already exist in this area?

    Newbie: Recursive lambda definitions?

    Submitted by dokondr on Sat, 03/18/2006 - 1:04pm.

    {-
    Haskell newbie: Recursive lambda definitions?
    Simon Thompson gives the following exercise (10.9) in his "Haskell. The Craft of Functional Programming" book:

    10.9 Define a function total

    total:: (Int -> Int) -> (Int -> Int)

    so that total f is the function which at value n gives the total

    f 0 + f 1 + ... + f n

    I use 'where' clause to describe the resulting function 'tot':
    -}

    total:: (Int -> Int) -> (Int -> Int)
    total f = tot 
        where
        tot n
    	| n >= 0 = (f n) + (tot (n-1))
    	| otherwise = 0
    
    test = total f1 4
    

    {-
    Q: Is it possible instead of naming and defining a resulting function (such as 'tot' in this example) just use recursive lambda definition? In this example recursion is required to create a function which is a variable sum of another function applications like:

    f 0 + f 1 + ... + f n

    Giving function a name ('tot' in this case) makes recursive definition possible. But what about lambda recursion? Can it be defined?
    -}

    Does Java lack recursion?

    Submitted by metaperl on Mon, 01/23/2006 - 8:34pm.

    In the same article Joel Spolsky seems to imply that it is impossible to do recursion in Java.

    I find that hard to believe...

    Google outstrips the competition via Functional Programming

    Submitted by metaperl on Mon, 01/23/2006 - 8:32pm.

    In the Perils of Java Schools, Joel Spoelsky states:

    Without understanding functional programming, you can't invent MapReduce, the algorithm that makes Google so massively scalable. The terms Map and Reduce come from Lisp and functional programming. MapReduce is, in retrospect, obvious to anyone who remembers from their 6.001-equivalent programming class that purely functional programs have no side effects and are thus trivially parallelizable. The very fact that Google invented MapReduce, and Microsoft didn't, says something about why Microsoft is still playing catch up trying to get basic search features to work, while Google has moved on to the next problem: building Skynet^H^H^H^H^H^H the world's largest massively parallel supercomputer. I don't think Microsoft completely understands just how far behind they are on that wave

    fibonacci hoe-down

    Submitted by metaperl on Sun, 12/18/2005 - 7:23pm.

    [17:00:07] > let fibs = 1:1:(zipWith (+) fibs (tail fibs)) in take 10 $ fibs
    [17:00:08] [1,1,2,3,5,8,13,21,34,55]
    [17:00:14] <_metaperl> the free haskell books are not very good
    [17:00:31] they're good enough for me, for now
    [17:00:35] thankyou
    [17:00:49] <_metaperl> jethr0: he did something like [ | x <- [1, 1] , y <- [2, ] ]
    [17:00:52] <_metaperl> I cant remember it
    [17:01:07] let fibs = [1,1] ++ [x + y | x <- fibs, y <- tail fibs] in take 10 $ fibs

    Search by Type

    Submitted by Greg Buchholz on Mon, 12/05/2005 - 12:37pm.
    Here's a random thought. What if we had a way to search for Haskell functions by type signature. Take the Hierarchical Libraries, slice/dice/index the type signatures so that you could search for "Num b => a -> b" and it would present you with a list of functions like length :: [a] -> Int. You'd also probably want to allow swizzling of the input arguments so that you could find "map" with a search like "[a] -> (a -> b) -> [b]". Then the next step would be to analyze your existing code to see if you've reinvented any wheels.