Skip to content
Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Another Haskell question

elbeno, 10 July, 200729 July, 2007

Which pattern is more efficient?

Pattern a:

circleSumA :: [Int] -> Int
circleSumA (i1 : is) = aux i1 is
    where aux i [] = i + i1
          aux i is = i + aux (head is) (tail is)

Pattern b:

circleSumB :: [Int] -> Int
circleSumB is = sum (is ++ [head is])

Is the Haskell compiler/interpreter able to make pattern b as efficient as pattern a? What about in the more general case where the operation is operating on more than 2 list elements? e.g. Folding a dot product over a list of points (obviously taking three points at a time to compute the dot product of the two vectors formed). In this case, Pattern b would have to perform 2 list appends (is ++ [head is] ++ [head (tail is)]). Would these get optimised?

Haskell

Post navigation

Previous post
Next post

Related Posts

Haskell wibblings

21 May, 200729 July, 2007

Well, this weekend I dived in with Haskell and started to make my way through The Haskell School of Expression. So I’ve been exercising neural pathways that haven’t seen a treadmill in a while, C++ programmer that I am. Overall, it’s been going well, and it’s giving me the feeling…

Read More

Haskell problem

8 July, 200729 July, 2007

Define a function makeChange that, given a nonnegative integer amount and a list of coin denominations, returns a list of the number of coins of each denomination required to make up the amount. For example: makeChange 99 [5,1] => [19,4] i.e. 19 nickels and 4 pennies equals 99 cents. To…

Read More

Functional Rainbow

29 December, 200829 December, 2008
Read More

Comments (4)

  1. auntysarah says:
    10 July, 2007 at 9:38 am

    Ooh, it's quite MLey isn't it? Looks kind of interesting – are there any good books on it?

    (http://livejournal.com/users/auntysarah)

  2. elbeno says:
    10 July, 2007 at 4:36 pm

    It's pretty nice. I first heard about its strong showings in recent ICFP programming contests. And I got interested when I discovered a real program written in it, viz. a GTK front end for Inform 7. I've been looking at FP lately, in particular purely applicative stuff, because ISTM that could be a good solution to getting parallelism on current and upcoming architectures.

    There are some online tutorials of course. I'm currently working my way through The Haskell School of Expression which is pretty good at more “real-world” stuff like drawing fractals in a window rather than writing factorial and prime sieving functions.

    (http://livejournal.com/users/elbeno)

  3. sylvene says:
    10 July, 2007 at 8:13 pm

    *burbles*

    Nerdy to the max, my friend. Nerdy to the max! I'll be in Santa Monica for E3. Whatcha doin'?

    Cheers!

    (http://livejournal.com/users/sylvene)

  4. elbeno says:
    10 July, 2007 at 9:16 pm

    Ah, E3 starts tomorrow. It's not really on my radar any more. I'll be working as normal.

    (http://livejournal.com/users/elbeno)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

©2026 Why is a raven like a writing desk? | WordPress Theme by SuperbThemes