Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:41:50+00:00 2026-05-26T20:41:50+00:00

This package has some functions to turn recursive functions into dynamic programming recursive functions,

  • 0

This package has some functions to turn recursive functions into dynamic programming recursive functions, for better performance:

http://hackage.haskell.org/packages/archive/data-memocombinators/0.3/doc/html/Data-MemoCombinators.html#t:Memo

Unfortunately, they only have an example for the simplest type of function, and there are no examples on how to use a function of 2 variables. Where can I find an example of how to, for example, turn [Int] -> Int -> Int function into a dynamic-programming function? The documentation says memo2 takes two Memos as first arguments, but I’m not sure what that means.

Solution:

As Hammar described, instead of defining a function as:

foo :: [Int] -> Int -> Int
foo list value = ...

to use memo2:

import qualified Data.MemoCombinators as Memo

foo = Memo.memo2 (Memo.list Memo.integral) Memo.integral foo'
  where ... (define foo' with recursive calls to foo.)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:41:50+00:00Added an answer on May 26, 2026 at 8:41 pm

    The library defines the type Memo a, which is a “memoizer” for functions taking arguments of type a. The key to understanding how to use this library is to understand how to use and compose these memoizers.

    In the simple case, you have a single argument function and a simple memoizer, for example a Fibonacci function and a memoizer for Integral arguments. In such a case, we obtain the memoized function by applying the memoizer to the function to be memoized:

     fib = Memo.integral fib'
       where
         fib' 0 = 0
         fib' 1 = 1
         fib' x = fib (x-1) + fib (x-2)
    

    Some memoizers take arguments to customize their behavior, for example arrayRange. In the following example, fib n will only be memoized if n is between 1 and 100.

    fib = Memo.arrayRange (1, 100) fib'
      where ...
    

    The library also provides combinators for building more complex memoizers out of simple ones. For example, list, which turns a memoizer for a into a memoizer for [a].

    Finally, to memoize functions of multiple arguments there are the functions memo2 and memo3, which take a memoizer for each argument plus a function and returns a memoized function.

    So to memoize your two-argument function, we will need to use memo2. We can use the integral memoizer for the Int argument, and for the [Int] argument we can use list integral. Putting this together, we get something like this:

    memo2 (list integral) integral foo
    

    However, you can also use more specific memoizers if you know the numbers are in some specified range. For example, if the numbers in the list are between 1 and 10 and the second argument is between 15 and 20:

    memo2 (list $ arrayRange (1, 10)) (arrayRange (15, 20)) foo
    

    Whether this makes sense or not, depends on your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have written a software package for a particular niche industry. This package has
I'm writing a module that has several methods. Let's consider this : package MyPackage;
My Java application has got a package structure similar to this: src/com/name/app src/com/name/app/do src/com/name/utils/db
I want to install this python package: http://pypi.python.org/pypi/netifaces/0.5 But I don't know how and
I'm in the process of documenting some of my functions for an R package
I have a base class like this: package MyClass; use vars qw/$ME list of
I have a standalone enum type defined, something like this: package my.pkg.types; public enum
I found this PECL package called threads , but there is not a release
To be specific, I was trying this code: package hello; public class Hello {
I installed from kubuntu's package management this handy pnglite library. It contains just one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.