Головна сторінка Груп Google
Довідка | Записатися
Допис з розмови How to use Data.Map?
Група, до якої ви додаєте допис, - група Usenet. Відтак, будь-хто в Інтернеті бачитиме вашу електронну адресу.
Вашу відповідь не було надіслано.
Ваш допис було надіслано
 
Від:
Кому:
Копія:
Продолжить:
Додати копію: | Додати продовження: | Редагувати тему
Тема:
Підтвердження:
З метою підтвердження введіть символи, які ви бачите на зображенні нижче або числа, які чуєте, натиснувши значок доступу. Прослухайте і введіть цифри, що чуєте
 
Aidan  
Переглянути профіль
 Більше налаштувань 19 Вер 2008, 05:13
Групи новин: comp.lang.haskell
Від: Aidan <awe...@gmail.com>
Дата: Fri, 19 Sep 2008 12:13:54 +1000
Локально: Пт 19 Вер 2008 05:13
Тема: How to use Data.Map?
Hello haskellers,

I have a question relating to the use of Data.Map.  I admit I havn't
fully understood all the concepts of functional programming yet, and
thus am having trouble understanding how one might employ the Data.Map type.

Consider the following python code:

===============
combos = dict()

def get_num_combos(n,r):
   if (n,r) not in combos:
     if r is 1:
       combos[(n,r)] = n
     else:
       combos[(n,r)] = sum(get_num_combos(x,r-1) for x in xrange(r-1,n))
   return combos[(n,r)]
===============

get_num_combos() returns the number of ways to select r items from a set
of n objects (I know there are more efficient ways to do this, but that
is not the point of this post).

I've had no trouble implementing the get_num_combos function in haskell
- very straight forward and simple... however, I cannot seem to find a
way to use Data.Map in place of python's dict().  The problem with that
is, without some form of caching, get_num_combos can take a very long
time to return the solution for certain inputs.  I'm not concerned about
long term caching of results, more that a Data.Map is used to cache
results and prevent the same calculation being performed more than once.

I'd also like to state ahead of time that this is not a homework
question... I know it sounds like one.  In fact it's inspired by problem
53 on projecteuler.net, which I was able to solve using the python
function above.  I'm now just curious as to how one might implement this
same algorithm in haskell

Thanks in advance.

Regards,

Aidan


Ви мусите увійти перед публікацією повідомлень.
Аби надіслати допис, будь ласка, спочатку приєднайтеся до цієї групи.
Будь ласка, поновіть своє прізвисько на сторінці налаштування передплати перед тим, як надіслати свій допис.
У вас немає права надсилання дописів до цієї групи.

Створити групу - Групи Google - Домівка Google - Правила користування послугою - Заява про конфіденційність і нерозголошення інформації
©2009 Google