[Haskell-cafe] memoization

2013-07-22 Thread Christopher Howard
When I previously asked about memoization, I got the impression that memoization is not something that just happens magically in Haskell. Yet, on a Haskell wiki page about Memoization , an example given is memoized_fib

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-22 Thread Richard A. O'Keefe
On 21/07/2013, at 7:36 AM, Evan Laforge wrote: > Just by coincidence, I recently wrote this: This is a BEAUTIFUL example. I think we may disagree about what it's an example OF, however. I found the code a little difficult to follow, but when that's fixed up, there's no longer any reason to want

Re: [Haskell-cafe] memoization

2013-07-22 Thread KC
Have you tried the compiler? On Sun, Jul 21, 2013 at 11:59 PM, Christopher Howard < christopher.how...@frigidcode.com> wrote: > When I previously asked about memoization, I got the impression that > memoization is not something that just happens magically in Haskell. Yet, > on a Haskell wiki pa

Re: [Haskell-cafe] memoization

2013-07-22 Thread Christopher Howard
On 07/21/2013 11:19 PM, KC wrote: > Have you tried the compiler? > No. Would that work differently some how? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] catching IO errors in a monad transformer stack

2013-07-22 Thread Eric Rasmussen
Thanks John. I'll try it out, along with Kmett's exceptions package I just found: http://hackage.haskell.org/packages/archive/exceptions/0.1.1/doc/html/Control-Monad-Catch.html I noticed on an issue for lens (https://github.com/ekmett/lens/issues/301) they switched to this since MonadCatchIO is d

Re: [Haskell-cafe] memoization

2013-07-22 Thread Chris Wong
> memoized_fib :: Int -> Integer > memoized_fib = (map fib [0 ..] !!) >where fib 0 = 0 > fib 1 = 1 > fib n = memoized_fib (n-2) + memoized_fib (n-1) > [.. snipped ..] > Could someone explain the technical details of why this works? Why is "map > fib [0 ..]" not recalculated

Re: [Haskell-cafe] memoization

2013-07-22 Thread Christopher Howard
On 07/21/2013 11:52 PM, Chris Wong wrote: > [.. snipped ..] > > A binding is memoized if, ignoring everything after the equals sign, > it looks like a constant. > > In other words, these are memoized: > > x = 2 > > Just x = blah > > (x, y) = blah > > f = \x -> x + 1 > -- f = ...

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-22 Thread Andreas Abel
Just today, my student asked me why the following program does nothing: {-# LANGUAGE CPP, GeneralizedNewtypeDeriving, BangPatterns #-} import Control.Monad import System.IO.Unsafe import Data.Array.IO import Data.IORef import Debug.Trace type LinearArray a = (Int, IORef Int, IOArray Int a) in

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-22 Thread Andreas Abel
On 20.07.13 9:36 PM, Evan Laforge wrote: However, I'm also not agitating for a non-recursive let, I think that ship has sailed. Besides, if it were added people would start wondering about non-recursive where, and it would introduce an exception to haskell's pretty consistently order-independent

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-22 Thread MigMit
On Jul 22, 2013, at 12:27 PM, Andreas Abel wrote: > On 20.07.13 9:36 PM, Evan Laforge wrote: >> However, I'm also not agitating for a non-recursive let, I think that >> ship has sailed. Besides, if it were added people would start >> wondering about non-recursive where, and it would introduce a

Re: [Haskell-cafe] catching IO errors in a monad transformer stack

2013-07-22 Thread John Lato
I don't think there's anything necessarily wrong with ekmett's exceptions package, but you should be aware that it may not do what you expect: module Foo where import Control.Monad.IO.Class import Control.Monad.Catch import Control.Exception (ArithException) f :: CatchT IO String f = catch (lift

Re: [Haskell-cafe] memoization

2013-07-22 Thread Tom Ellis
On Mon, Jul 22, 2013 at 12:02:54AM -0800, Christopher Howard wrote: > > A binding is memoized if, ignoring everything after the equals sign, > > it looks like a constant. [...] > Thanks. That's very helpful to know. Yet, it seems rather strange and > arbitrary that "f x = ..." and "f = \x -> ..." w

Re: [Haskell-cafe] memoization

2013-07-22 Thread Tom Ellis
On Mon, Jul 22, 2013 at 07:52:06PM +1200, Chris Wong wrote: > A binding is memoized if, ignoring everything after the equals sign, > it looks like a constant. > > In other words, these are memoized: [...] > f = \x -> x + 1 [...] > and these are not: > > f x = x + 1 In what sense is the f

Re: [Haskell-cafe] memoization

2013-07-22 Thread 14875
in this case, neither of them is memoized. because they don't have any data in expressions. "memoized" is for constants who have data structure in its expression 2013/7/22 Tom Ellis > On Mon, Jul 22, 2013 at 07:52:06PM +1200, Chris Wong wrote: > > A binding is memoized if, ignoring everything a

Re: [Haskell-cafe] memoization

2013-07-22 Thread Andreas Abel
On 22.07.2013 09:52, Chris Wong wrote: memoized_fib :: Int -> Integer memoized_fib = (map fib [0 ..] !!) where fib 0 = 0 fib 1 = 1 fib n = memoized_fib (n-2) + memoized_fib (n-1) [.. snipped ..] Could someone explain the technical details of why this works? Why is "ma

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-22 Thread Andreas Abel
On 22.07.2013 10:50, MigMit wrote: On Jul 22, 2013, at 12:27 PM, Andreas Abel wrote: On 20.07.13 9:36 PM, Evan Laforge wrote: However, I'm also not agitating for a non-recursive let, I think that ship has sailed. Besides, if it were added people would start wondering about non-recursive whe

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-22 Thread Edward Kmett
let x = x +1 is perfectly cromulent when x is sufficiently lazy, e.g. in the one point compactification of the naturals: data Conat = S Conat | Z There it represents infinity with proper sharing. -Edward On Jul 22, 2013, at 10:24 AM, Andreas Abel wrote: > On 22.07.2013 10:50, MigMit wrote:

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-22 Thread i c
On Wed, Jul 10, 2013 at 9:47 AM, wrote: > > Jon Fairbairn wrote: > > It just changes forgetting to use different variable names because of > > recursion (which is currently uniform throughout the language) to > > forgetting to use non recursive let instead of let. > > Let me bring to the record t

[Haskell-cafe] Expression problem in the database?

2013-07-22 Thread Manuel Gómez
Hi café, I don’t know whether this is a good forum to ask about this —perhaps Stack Overflow is better suited—, but since Haskell and related languages are so finely fit for good solutions to the expression problem, I figure this list may have a few helpful pointers regarding this problem. I’m fa

Re: [Haskell-cafe] memoization

2013-07-22 Thread Christopher Howard
On 07/22/2013 06:16 AM, Andreas Abel wrote: > On 22.07.2013 09:52, Chris Wong wrote: > > True, but the essential thing to be memoized is not memoized_fib, > which is a function, but the subexpression > > map fib [0..] > > which is an infinite list, i.e., a value. > > The rule must be like "in > >

Re: [Haskell-cafe] memoization

2013-07-22 Thread Tom Ellis
On Mon, Jul 22, 2013 at 04:16:19PM +0200, Andreas Abel wrote: > In general, I would not trust such compiler magic, but just let-bind > anything I want memoized myself: > > memoized_fib :: Int -> Integer > memoized_fib x = fibs !! x > where fibs = map fib [0..] -- lazily computed infinite li

Re: [Haskell-cafe] memoization

2013-07-22 Thread wren ng thornton
On 7/22/13 9:06 AM, Tom Ellis wrote: > On Mon, Jul 22, 2013 at 07:52:06PM +1200, Chris Wong wrote: >> A binding is memoized if, ignoring everything after the equals sign, >> it looks like a constant. >> >> In other words, these are memoized: > [...] >> f = \x -> x + 1 > [...] >> and these are

Re: [Haskell-cafe] memoization

2013-07-22 Thread David Thomas
I, for one, would love to have a compiler do (a) based on (b), my specification of (c), and the ability to pin particular things... On Mon, Jul 22, 2013 at 4:04 PM, wren ng thornton wrote: > On 7/22/13 9:06 AM, Tom Ellis wrote: > > On Mon, Jul 22, 2013 at 07:52:06PM +1200, Chris Wong wrote: > >

Re: [Haskell-cafe] Proposal: Non-recursive let

2013-07-22 Thread Richard A. O'Keefe
On 22/07/2013, at 8:14 PM, Andreas Abel wrote: > Just today, my student asked me why the following program does nothing: Did you ask your student why their code should not be torn into pieces, burned to ashes, and incorporated into a pot for radioactive waste? All those occurrences of unsafePer

Re: [Haskell-cafe] memoization

2013-07-22 Thread Christopher Howard
On 07/22/2013 03:41 PM, David Thomas wrote: > I, for one, would love to have a compiler do (a) based on (b), my > specification of (c), and the ability to pin particular things... > > The reason it is a big deal to me is it sometimes the more natural-looking (read, declarative) way of writing a fu

Re: [Haskell-cafe] memoization

2013-07-22 Thread Tom Ellis
On Mon, Jul 22, 2013 at 04:04:33PM -0700, wren ng thornton wrote: > Consider rather, > > f1 = let y = blah blah in \x -> x + y > > f2 x = let y = blah blah in x + y > > The former will memoize y and share it across all invocations of f1; > whereas f2 will recompute y for each invocation