2024/05/16

Newest at the top

2024-05-16 17:50:57 +0200 <ski> are you sure you have two arrays, and not two lists ?
2024-05-16 17:50:34 +0200 <ski> are `[Int]',`Int',`[Int]' your parameter types ?
2024-05-16 17:50:00 +0200 <Guest13> if it helps, I can explain the problem
2024-05-16 17:49:36 +0200 <Guest13> im not sure I can, the state I have is 2 arrays which im comparing to each other and an integer to denote a counter and a string
2024-05-16 17:49:30 +0200 <lambdabot> 144
2024-05-16 17:49:28 +0200 <ski> > let memoFib n | n >= 0 = fibs ! n where fibs = L.tabulate (0,n) (\n -> case n of 0 -> 0; 1 -> 1; n -> fibs ! (n - 1) + fibs ! (n - 2)) in memoFib 12 -- array `fibs' is (lazily) recursively defined in terms of itself
2024-05-16 17:48:44 +0200 <ski> the array `fibs' and the function `fib' are mutually recursively defined. you can inline one into the other as
2024-05-16 17:48:12 +0200 <ski> Guest13 : can you follow that ^ example ? given a (non-negative) integer `n', it builds an array (`fibs') with `n+1' elements (indexed from `0' to `1'), with elements set by the fibonacci function (`fib') where recursive calls look up results in the array, and so will be cached (the array elements are lazily computed)
2024-05-16 17:48:01 +0200 <Guest13> the problem I have is that each recursive call is defined by [Int], Int, [Int]
2024-05-16 17:46:33 +0200 <lambdabot> 144
2024-05-16 17:46:32 +0200 <ski> > let memoFib n | n >= 0 = fibs ! n where fibs = L.tabulate (0,n) fib; fib 0 = 0; fib 1 = 1; fib n = fibs ! (n - 1) + fibs ! (n - 2) in memoFib 12
2024-05-16 17:43:51 +0200 <lambdabot> array (-2,3) [(-2,4),(-1,1),(0,0),(1,1),(2,4),(3,9)]
2024-05-16 17:43:49 +0200 <ski> > L.tabulate (-2,3) (\i -> i^2) -- construct an array, with each element based on its index
2024-05-16 17:42:22 +0200 <lambdabot> Defined.
2024-05-16 17:42:21 +0200 <ski> @let tabulate :: Ix i => (i,i) -> (i -> e) -> Array i e; tabulate ix f = listArray ix [f i | i <- range ix]
2024-05-16 17:41:02 +0200 <ski> `rec' is for something else (recursive bindings in `do')
2024-05-16 17:40:41 +0200 <ski> there is no state, adding to the map, unless you express this with state in some fashion .. and it's probably better to avoid that, if you can
2024-05-16 17:38:50 +0200 <Guest13> I've seen the rec keyword but this is also something I am unsure about
2024-05-16 17:38:24 +0200 <Guest13> ie adds to the map, or checks the map
2024-05-16 17:38:01 +0200 <Guest13> I can't think about it functionally very well, I am thinking that each time it does a call it updates an internal "state"
2024-05-16 17:37:26 +0200 <Guest13> I understand to use a map but I don't know how I would implement it
2024-05-16 17:36:42 +0200zzz(~yin@user/zero)
2024-05-16 17:33:37 +0200 <ski> .. but if your domain is large, the map would also be large. sometimes you can allocate the association structure itself, lazily, incrementally (like the infinite linked list above)
2024-05-16 17:32:32 +0200 <ski> anyway, if you already know from the start (perhaps from the initial parameters) how large domain you need for the recursive calls corresponding to subproblems of that initial problem, you can allocate a map (recursively defined) that has an association mapping each element of your domain to the corresponding result value (lazily computed)
2024-05-16 17:30:46 +0200 <ski> (oh, and jfyi, that `memo_fib' still uses `fib' (but not `memo_fib') for each individual call, so not reusing the list resulting from the `map' as a cache)
2024-05-16 17:29:08 +0200 <ski> .. or how large is your domain ?
2024-05-16 17:28:48 +0200 <ski> so use a map ?
2024-05-16 17:24:21 +0200 <Guest13> it is the sort of problem where I would want to have a map to store previous calls
2024-05-16 17:23:23 +0200 <Guest13> hi, how can I memoize recursive calls that aren't simple like the fibonacci. I see on the wiki for memoization there is an example memo_fib= (map fib [1..] !!), but the problem I am trying to solve has the recursive calls in an order I don't necessarily know
2024-05-16 17:21:36 +0200waleee(~waleee@h-176-10-144-38.NA.cust.bahnhof.se) (Ping timeout: 255 seconds)
2024-05-16 17:18:48 +0200califax(~califax@user/califx)
2024-05-16 17:18:33 +0200neiluj(~neiluj@193.203.71.162)
2024-05-16 17:18:28 +0200Square2(~Square4@user/square) (Ping timeout: 260 seconds)
2024-05-16 17:15:01 +0200califax(~califax@user/califx) (Remote host closed the connection)
2024-05-16 17:14:18 +0200chele(~chele@user/chele) (Remote host closed the connection)
2024-05-16 17:10:16 +0200califax(~califax@user/califx)
2024-05-16 17:08:23 +0200califax(~califax@user/califx) (Remote host closed the connection)
2024-05-16 17:05:25 +0200zzz(~yin@user/zero) (Ping timeout: 255 seconds)
2024-05-16 17:04:30 +0200Guest13(~Guest13@cpc93370-hers8-2-0-cust590.6-3.cable.virginm.net)
2024-05-16 17:03:23 +0200ocra8(ocra8@user/ocra8)
2024-05-16 17:02:33 +0200neiluj(~neiluj@193.203.71.162) (Ping timeout: 256 seconds)
2024-05-16 16:56:41 +0200Square2(~Square4@user/square)
2024-05-16 16:51:52 +0200califax(~califax@user/califx)
2024-05-16 16:51:27 +0200random-jellyfish(~developer@user/random-jellyfish)
2024-05-16 16:51:27 +0200random-jellyfish(~developer@2a02:2f04:11e:c600:4e7a:622:23f0:da46) (Changing host)
2024-05-16 16:51:27 +0200random-jellyfish(~developer@2a02:2f04:11e:c600:4e7a:622:23f0:da46)
2024-05-16 16:49:51 +0200califax(~califax@user/califx) (Remote host closed the connection)
2024-05-16 16:48:17 +0200califax(~califax@user/califx)
2024-05-16 16:47:18 +0200Square2(~Square4@user/square) (Ping timeout: 256 seconds)
2024-05-16 16:43:45 +0200califax(~califax@user/califx) (Remote host closed the connection)