Re: [Haskell-cafe] Template Haskell tutorials?

2011-04-14 Thread Zoe Clifford
On Wed, Apr 13, 2011 at 10:43 PM, Kenneth Hoste kenneth.ho...@gmail.com wrote:
 Hi,
 The links to the supposedly brilliant Template Haskell tutorials by Bulat are 
 broken.

 http://www.haskell.org/bz/thdoc.htm
 http://www.haskell.org/bz/th3.htm

 Does anyone know if these tutorials moved to somewhere else?

 greetings,
 Kenneth

 If all else fails, it's still accessable via the wayback machine.

http://replay.waybackmachine.org/20090418034412/http://www.haskell.org/bz/thdoc.htm

and

http://replay.waybackmachine.org/20090421010040/http://www.haskell.org/bz/th3.htm

-Zoe
(hopefully I've figured out this mailing list thing right)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?

2011-04-14 Thread Dmitri O.Kondratiev
Hello,
I am looking for a site providing on-line automatic judge for Programming
Challenges that can be coded in Haskell.
For example this site:
http://www.programming-challenges.com
provides lots of interesting programming provlems:
http://www.programming-challenges.com/pg.php?page=index

Yet, unfortunately only C, C++ and Java code can be submitted,  judge on
that site can't compile and run Haskell code.
Is there any similar online judge for Haskell?

Thanks,
Dmitri
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?

2011-04-14 Thread Angel de Vicente

Hi

On 14/04/11 10:29, Dmitri O.Kondratiev wrote:

I am looking for a site providing on-line automatic judge for
Programming Challenges that can be coded in Haskell.
For example this site:
http://www.programming-challenges.com
provides lots of interesting programming provlems:
http://www.programming-challenges.com/pg.php?page=index

Yet, unfortunately only C, C++ and Java code can be submitted,  judge on
that site can't compile and run Haskell code.
Is there any similar online judge for Haskell?


You can try http://www.spoj.pl/

Cheers,
Ángel
--
http://www.iac.es/galeria/angelv/

High Performance Computing Support PostDoc
Instituto de Astrofísica de Canarias
-
ADVERTENCIA: Sobre la privacidad y cumplimiento de la Ley de Protección de 
Datos, acceda a http://www.iac.es/disclaimer.php
WARNING: For more information on privacy and fulfilment of the Law concerning 
the Protection of Data, consult http://www.iac.es/disclaimer.php?lang=en


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IO and Cont as monads

2011-04-14 Thread Roel van Dijk
On 13 April 2011 21:26, Tim Chevalier catamorph...@gmail.com wrote:
 IO doesn't obey the monad laws, due to the presence of seq in Haskell.
 Sad but true...

See also a previous discussion about IO and the Monad laws:

http://www.haskell.org/pipermail/haskell-cafe/2010-March/074001.html

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?

2011-04-14 Thread Pedro Vasconcelos
On Thu, 14 Apr 2011 13:29:48 +0400
Dmitri O.Kondratiev doko...@gmail.com wrote:

 Hello,
 I am looking for a site providing on-line automatic judge for
 Programming Challenges that can be coded in Haskell.
 For example this site:
 http://www.programming-challenges.com
 provides lots of interesting programming provlems:
 http://www.programming-challenges.com/pg.php?page=index
 
 Yet, unfortunately only C, C++ and Java code can be submitted,  judge
 on that site can't compile and run Haskell code.
 Is there any similar online judge for Haskell?
 
 Thanks,
 Dmitri

Althpugh not Haskell-specific, the Mooshak system for managing
programming contests on the Web allows you to configure most programming
languages:

http://mooshak.dcc.fc.up.pt/

It's been developed our CS department and used internally and
externally for programming contests and courses.

Pedro

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Dmitri O.Kondratiev
3n+1 is the first, warm-up problem at Programming Chalenges site:
http://www.programming-challenges.com/pg.php?page=downloadproblemprobid=110101format=html

(This problem illustrates Collatz conjecture:
http://en.wikipedia.org/wiki/3n_%2B_1#Program_to_calculate_Collatz_sequences
)

As long as the judge on this site takes only C and Java solutions, I
submitted in Java some add-hock code (see at the end of this message) where
I used recursion and a cache of computed cycles. Judge accepted my code and
measured  0.292 sec with best overall submissions of 0.008 sec to solve the
problem.

*** Question: I wonder how to implement cache for this problem in Haskell?
At the moment, I am not so much interested in the speed of the code, as in
nice implementation.

To illustrate my question I add the problem description and my Java solution
at the end of this message.
Thanks!

*** Problem

Consider the following algorithm to generate a sequence of numbers. Start
with an integer *n*. If *n* is even, divide by 2. If *n* is odd, multiply by
3 and add 1. Repeat this process with the new value of *n*, terminating
when *n* = 1. For example, the following sequence of numbers will be
generated for *n* = 22:
22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
It is *conjectured* (but not yet proven) that this algorithm will terminate
at *n* = 1 for every integer *n*. Still, the conjecture holds for all
integers up to at least 1, 000, 000.

For an input *n*, the *cycle-length* of *n* is the number of numbers
generated up to and *including* the 1. In the example above, the cycle
length of 22 is 16. Given any two numbers *i* and *j*, you are to determine
the maximum cycle length over all numbers between *i* and *j*, *including* both
endpoints.

InputThe input will consist of a series of pairs of integers *i* and *j*,
one pair of integers per line. All integers will be less than 1,000,000 and
greater than 0.

OutputFor each pair of input integers *i* and *j*, output *i*, *j* in the
same order in which they appeared in the input and then the maximum cycle
length for integers between and including *i* and *j*. These three numbers
should be separated by one space, with all three numbers on one line and
with one line of output for each line of input.

Sample Input

1 10
100 200
201 210
900 1000

Sample Output

1 10 20
100 200 125
201 210 89
900 1000 174

*** my Java solution

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
final static BufferedReader reader_ = new BufferedReader(new
InputStreamReader(System.in));
/**
 * @param args
 */
public static void main(String[] args) {
new Problem().run();
}   
static String[] ReadLn() {
String[] tokens = null;
try {
String line = reader_.readLine();
String REGEX_WHITESPACE = \\s+;
String cleanLine = 
line.trim().replaceAll(REGEX_WHITESPACE,  );
tokens = cleanLine.split(REGEX_WHITESPACE); 

} catch (Exception e) {}
return tokens;
}
}

class Problem implements Runnable {
long CACHE_SIZE = 65536;
private final long[] cache_ = new long[(int) CACHE_SIZE];
/**
 * Compute cycle length for a single number
 *
 * @param n number for which we find cycle length
 * @return cycle length
 */ 
long cycleLen(long n) {
long len = 1;
if (n != 1) {
len = getFromCache(n);
if (len == 0) { //not yet in cache
// Recursively compute and store all 
intermediate values of cycle length
if ((n  1) == 0) {
len = 1 + cycleLen(n  1);
} else {
len = 1 + cycleLen(n * 3 + 1);
}
putInCache(n, len);
}
}
return len;
}

void putInCache(long n, long len) {
if(n  CACHE_SIZE) {
cache_[(int)n] = len;
}
}

long getFromCache(long n) {
long result = 0;
if(n  CACHE_SIZE) {
result = cache_[(int)n];
}
return result;
}

/**
 * Find max cycle on interval
 *
 * @param from interval start
 * @param to interval end
 * @return max cycle
 */
Long maxCycle(Long from, Long to) {
Long result = 0L;
Long cycle = 0L;
// Get all values of cycle length on the interval and put these
values into a sorted set

Re: [Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?

2011-04-14 Thread Mats Rauhala
http://codechef.com accepts Haskell entries.


pgpa3li6zz0gF.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Felipe Almeida Lessa
This is very similar to the Problem 14 on Project Euler [1].  Should
you really want a nice solution in Haskell, and noting that this is a
big spoiler, there are some on the wiki [2].  But I highly recommend
you to try coding your own solutions before looking at the site =).

Cheers!

[1] http://projecteuler.net/index.php?section=problemsid=14
[2] http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_14

-- 
Felipe.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?

2011-04-14 Thread Dmitri O.Kondratiev
Angel de Vicente wrote:

On 14/04/11 10:29, Dmitri O.Kondratiev wrote:
* I am looking for a site providing on-line automatic judge for
** Programming Challenges that can be coded in Haskell.
** For example this site:
** http://www.programming-challenges.com
** provides lots of interesting programming provlems:
** http://www.programming-challenges.com/pg.php?page=index
*
* Yet, unfortunately only C, C++ and Java code can be submitted, judge on
** that site can't compile and run Haskell code.
** Is there any similar online judge for Haskell?
* You can try http://www.spoj.pl/
Cheers,
Ángel

Angel, thanks!
This site looks good. Do you know if spoj.pl has a search utility for
problems?
It would be great if they have 3n+1 problem I wrote about in a separate
thread here.

-- 
All the best,
Dmitri O. Kondratiev

This is what keeps me going: discovery
doko...@gmail.com
http://sites.google.com/site/dokondr/welcome
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Steven Keuchel
Hi Dmitri,

As a reference you might want to take a look at the Project Euler
problem #14 and the corresponding dubious entry in the HaskellWiki:
http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_14
.

 *** Question: I wonder how to implement cache for this problem in Haskell?
 At the moment, I am not so much interested in the speed of the code, as in
 nice implementation.

a while ago I wondered about the same question: memoization and more
specifically tabulation (DP) in Haskell. After some time I came up
with code which does it IMO in a fairly nice way using an array of
lazy computations which gives you top-down DP for free at the expense
of performance. Another way is to use lazily built tries ala MemoTrie:
http://www.haskell.org/haskellwiki/MemoTrie .

Specific implementation:

 import Data.Array
 import Data.MemoTrie

I write the collatz function using open recursion in order to separate
the recursive function from the memo scheme.

 type Gen a = a - a
 type Fix a = Gen a - a

 collatzGen :: Gen (Integer - Integer)
 collatzGen c 1 = 1
 collatzGen c n | even n= 1 + c (div n 2)
| otherwise = 1 + c (3*n + 1)

We can use plain old Data.Function.fix to get the usual stupid
recursive function or use our custom fixpoint combinators. |fixtab|
for example uses an array to cache the result in the given range. When
the argument is outside of the range the normal recursive scheme is
applied.

 fixtab :: Ix i = (i, i) - Fix (i - r)
 fixtab b f = f'
   where a= listArray b [ f f' i | i - range b ]
 f' i = if inRange b i then a!i else f f' i

Another option is to use the MemoTrie package where we can write a
fixpoint combinator like this:
 fixmemo :: HasTrie i = Fix (i - r)
 fixmemo f = let m = memo (f m); in m

And of course the final collatz function:
 collatz :: Integer - Integer
 collatz = fixtab (1,100) collatzGen

Cheers,
Steven

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Dmitri O.Kondratiev
Thanks, Felipe!
Sure I will try to code solution myself. Doing it all by yourself is the
main fun of everything, isn't it?
I was just asking about the *idea* of implementing cache in Haskell, in
general, not just in this case only.

On Thu, Apr 14, 2011 at 3:11 PM, Felipe Almeida Lessa 
felipe.le...@gmail.com wrote:

 This is very similar to the Problem 14 on Project Euler [1].  Should
 you really want a nice solution in Haskell, and noting that this is a
 big spoiler, there are some on the wiki [2].  But I highly recommend
 you to try coding your own solutions before looking at the site =).

 Cheers!

 [1] http://projecteuler.net/index.php?section=problemsid=14
 [2] http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_14

 --
 Felipe.



-- 
All the best,
Dmitri O. Kondratiev

This is what keeps me going: discovery
doko...@gmail.com
http://sites.google.com/site/dokondr/welcome
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Ryan Ingram
So if we were to emulate your Java solution, we'd do

import Data.Array

cacheSize :: Int
cacheSize = 65536

table :: Array Int Integer
table = listArray (1,cacheSize) (1 : map go [2..cacheSize]) where
go n
| even n = 1 + lookup (n `div` 2)
| otherwise = 1 + lookup (3 * n + 1)

lookup :: Integer - Integer
lookup n
| n  cacheSize = table ! (fromInteger n)
| even n = 1 + lookup (n `div` 2)
| otherwise = 1 + lookup (3 * n + 1)

The rest of the code is just some simple i/o.

The table is filled up lazily as you request values from it.

On Thu, Apr 14, 2011 at 3:29 AM, Dmitri O.Kondratiev doko...@gmail.comwrote:

 3n+1 is the first, warm-up problem at Programming Chalenges site:

 http://www.programming-challenges.com/pg.php?page=downloadproblemprobid=110101format=html

 (This problem illustrates Collatz conjecture:

 http://en.wikipedia.org/wiki/3n_%2B_1#Program_to_calculate_Collatz_sequences
 )

 As long as the judge on this site takes only C and Java solutions, I
 submitted in Java some add-hock code (see at the end of this message) where
 I used recursion and a cache of computed cycles. Judge accepted my code and
 measured  0.292 sec with best overall submissions of 0.008 sec to solve the
 problem.

 *** Question: I wonder how to implement cache for this problem in Haskell?
 At the moment, I am not so much interested in the speed of the code, as in
 nice implementation.

 To illustrate my question I add the problem description and my Java
 solution at the end of this message.
 Thanks!

 *** Problem

 Consider the following algorithm to generate a sequence of numbers. Start
 with an integer *n*. If *n* is even, divide by 2. If *n* is odd, multiply
 by 3 and add 1. Repeat this process with the new value of *n*, terminating
 when *n* = 1. For example, the following sequence of numbers will be
 generated for *n* = 22:
 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
 It is *conjectured* (but not yet proven) that this algorithm will
 terminate at *n* = 1 for every integer *n*. Still, the conjecture holds
 for all integers up to at least 1, 000, 000.

 For an input *n*, the *cycle-length* of *n* is the number of numbers
 generated up to and *including* the 1. In the example above, the cycle
 length of 22 is 16. Given any two numbers *i* and *j*, you are to
 determine the maximum cycle length over all numbers between *i* and *j*, *
 including* both endpoints.

 Input The input will consist of a series of pairs of integers *i* and *j*,
 one pair of integers per line. All integers will be less than 1,000,000 and
 greater than 0.

 OutputFor each pair of input integers *i* and *j*, output *i*, *j* in the
 same order in which they appeared in the input and then the maximum cycle
 length for integers between and including *i* and *j*. These three numbers
 should be separated by one space, with all three numbers on one line and
 with one line of output for each line of input.

 Sample Input

 1 10
 100 200
 201 210
 900 1000

 Sample Output

 1 10 20
 100 200 125
 201 210 89
 900 1000 174

 *** my Java solution

 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 public class Main {
   final static BufferedReader reader_ = new BufferedReader(new 
 InputStreamReader(System.in));
   /**
* @param args
*/
   public static void main(String[] args) {
   new Problem().run();
   }   
   static String[] ReadLn() {
   String[] tokens = null;
   try {
   String line = reader_.readLine();
   String REGEX_WHITESPACE = \\s+;
   String cleanLine = 
 line.trim().replaceAll(REGEX_WHITESPACE,  );
   tokens = cleanLine.split(REGEX_WHITESPACE); 
 
   } catch (Exception e) {}
   return tokens;
   }
 }

 class Problem implements Runnable {
   long CACHE_SIZE = 65536;
   private final long[] cache_ = new long[(int) CACHE_SIZE];
   /**
* Compute cycle length for a single number
*
* @param n number for which we find cycle length
* @return cycle length
*/ 
   long cycleLen(long n) {
   long len = 1;
   if (n != 1) {
   len = getFromCache(n);
   if (len == 0) { //not yet in cache
   // Recursively compute and store all 
 intermediate values of cycle length
   if ((n  1) == 0) {
   len = 1 + cycleLen(n  1);
   } else {
   len = 1 + cycleLen(n * 3 + 1);
   }
   putInCache(n, len);
   }
   }
   return len;
   }
   
   void putInCache(long n, long len) {
   if(n  CACHE_SIZE) {
   

Re: [Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?

2011-04-14 Thread Angel de Vicente

Hi,

On 14/04/11 12:16, Dmitri O.Kondratiev wrote:

Angel, thanks!
This site looks good. Do you know if spoj.pl http://spoj.pl has a
search utility for problems?
It would be great if they have 3n+1 problem I wrote about in a separate
thread here.


yes they have a search utility. Searching for 3n+1, one of the problems 
that comes up is the problem with ID: 4073 
(http://www.spoj.pl/problems/PROBTNPO/), but I don't know if that is the 
problem you were talking about.


Ángel
--
http://www.iac.es/galeria/angelv/

High Performance Computing Support PostDoc
Instituto de Astrofísica de Canarias
-
ADVERTENCIA: Sobre la privacidad y cumplimiento de la Ley de Protección de 
Datos, acceda a http://www.iac.es/disclaimer.php
WARNING: For more information on privacy and fulfilment of the Law concerning 
the Protection of Data, consult http://www.iac.es/disclaimer.php?lang=en


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Dmitri O.Kondratiev
Thanks, everybody!
Your feedback is a great food for my mind (as Lewis Carroll once wrote :)
When asking how to implement cache in Haskell I was hopping that there
exists some solution without using Data.Array, more functional approach,
if I may say so  ...
I must be wrong, though (need more time to fully comprehend solution that
Steven described in this thread ).

On Thu, Apr 14, 2011 at 3:22 PM, Ryan Ingram ryani.s...@gmail.com wrote:

 So if we were to emulate your Java solution, we'd do

 import Data.Array

 cacheSize :: Int
 cacheSize = 65536

 table :: Array Int Integer
 table = listArray (1,cacheSize) (1 : map go [2..cacheSize]) where
 go n
 | even n = 1 + lookup (n `div` 2)
 | otherwise = 1 + lookup (3 * n + 1)

 lookup :: Integer - Integer
 lookup n
 | n  cacheSize = table ! (fromInteger n)
 | even n = 1 + lookup (n `div` 2)
 | otherwise = 1 + lookup (3 * n + 1)

 The rest of the code is just some simple i/o.

 The table is filled up lazily as you request values from it.


 --
All the best,
Dmitri O. Kondratiev

This is what keeps me going: discovery
doko...@gmail.com
http://sites.google.com/site/dokondr/welcome
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Christian Maeder

Am 14.04.2011 12:29, schrieb Dmitri O.Kondratiev:

3n+1 is the first, warm-up problem at Programming Chalenges site:
http://www.programming-challenges.com/pg.php?page=downloadproblemprobid=110101format=html
http://www.programming-challenges.com/pg.php?page=downloadproblemprobid=110101format=html

(This problem illustrates Collatz conjecture:
http://en.wikipedia.org/wiki/3n_%2B_1#Program_to_calculate_Collatz_sequences)

As long as the judge on this site takes only C and Java solutions, I
submitted in Java some add-hock code (see at the end of this message)
where I used recursion and a cache of computed cycles. Judge accepted my
code and measured  0.292 sec with best overall submissions of 0.008 sec
to solve the problem.

*** Question: I wonder how to implement cache for this problem in
Haskell? At the moment, I am not so much interested in the speed of the
code, as in nice implementation.


I'ld use something like:

import qualified Data.Map as Map

addToMap :: Integer - Map.Map Integer Integer
  - Map.Map Integer Integer
addToMap n m = case Map.lookup n m of
  Nothing - let
l = if even n then div n 2 else 3 * n + 1
p = addToMap l m
Just s = Map.lookup l p
in Map.insert n (s + 1) p
  Just _ - m

addRangeToMap :: Integer - Integer - Map.Map Integer Integer
  - Map.Map Integer Integer
addRangeToMap i j m = if j  i then m else
  addRangeToMap i (j - 1) $ addToMap j m

getMaxLength :: Integer - Integer - Map.Map Integer Integer - Integer
getMaxLength i j =
Map.foldWithKey (\ k l - if i  k || k  j then id else max l) 0

-- putting it all togeter
getRangeMax :: Integer - Integer - Integer
getRangeMax i j = getMaxLength i j $ addRangeToMap i j
  $ Map.singleton 1 1

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Chris Dew
This is a question about the use of type classes in Haskell.

I get an error (below) when trying to compile the code (below and at
https://github.com/chrisdew/haskell-sandbox/blob/master/not_working_but_clean.hs
).

As someone just learning Haskell, I have tried following GHC's advice,
but I think the cause is different.

I believe the problem is that either of the types 'IO String' or plain
'String' could be the type of 'lhello - lbracket', but GHC doesn't
know which.

The problem is that it doesn't matter, either type would work fine.

I have posted a working version of the code at
https://github.com/chrisdew/haskell-sandbox/blob/master/working_but_ugly.hs
.  This replaces one of the - operators with a new (non type class)
operator '-' which forces 'lhello - lbracket' to be of type 'IO
String'.

* Is my analysis correct?  Or is there something else going on here?

* Is there any way of informing GHC what the type of 'lhello -
lbracket' doen't matter and that is should just chose either of the
two possibilities.  Or perhaps theres a LANGUAGE option which will let
me specify that 'lastest declared matching instance of the class wins'
if anything is undecided.

Thanks,

Chris.


Error:
chris@chris-linux-desktop:~/nonworkspace/haskell-sandbox$ ghc
not_working_but_clean.hs

not_working_but_clean.hs:40:16:
No instance for (Stream (IO String) (IO String) (IO String) d)
  arising from a use of `-' at not_working_but_clean.hs:40:16-34
Possible fix:
  add an instance declaration for
  (Stream (IO String) (IO String) (IO String) d)
In the first argument of `(-)', namely `lhello - lbracket'
In the second argument of `($)', namely
`lhello - lbracket - putStrLn'
In a stmt of a 'do' expression:
  forkIO $ lhello - lbracket - putStrLn

not_working_but_clean.hs:40:16:
No instance for (Stream d String (IO ()) (IO ()))
  arising from a use of `-' at not_working_but_clean.hs:40:16-47
Possible fix:
  add an instance declaration for (Stream d String (IO ()) (IO ()))
In the second argument of `($)', namely
`lhello - lbracket - putStrLn'
In a stmt of a 'do' expression:
  forkIO $ lhello - lbracket - putStrLn
In the expression:
do { forkIO $ (bracket $ hello) - putStrLn;
 forkIO $ lhello - lbracket - putStrLn;
 forkIO $ bracket hello - putStrLn;
 forkIO $ lbracket lhello - putStrLn;
    }



not_working_but_clean.hs:
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances,
TypeSynonymInstances, OverlappingInstances #-}
{-# OPTIONS_GHC #-}

module Main (
main
)
where

import Control.Concurrent (forkIO, MVar, newEmptyMVar, putMVar,
takeMVar, ThreadId, threadDelay)
import Control.Monad (forever, liftM)

class Stream a b c d where
(-) :: a - (b - c) - d

instance Stream (IO d) d (IO c) (IO c) where
f - g = f = g

instance Stream d d (IO c) (IO c) where
f - g = g f

instance Stream d d c c where
x - y = y $ x

-- This simply wraps a string in brackets.
bracket :: String - String
bracket x = ( ++ x ++ )

lbracket :: IO String - IO String
lbracket x = liftM bracket x

hello :: String
hello = Hello World!

lhello :: IO String
lhello = do return hello

main :: IO ()
main = do
   forkIO $ (bracket $ hello) - putStrLn
   forkIO $ lhello - lbracket - putStrLn
   forkIO $ bracket hello - putStrLn
   forkIO $ lbracket lhello - putStrLn
   threadDelay 1000 -- Sleep for at least 10 seconds before exiting.



working_but_ugly.hs:
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances,
TypeSynonymInstances, OverlappingInstances #-}
{-# OPTIONS_GHC #-}

module Main (
main
)
where

import Control.Concurrent (forkIO, MVar, newEmptyMVar, putMVar,
takeMVar, ThreadId, threadDelay)
import Control.Monad (forever, liftM)

class Stream a b c d where
(-) :: a - (b - c) - d

instance Stream (IO d) d (IO c) (IO c) where
f - g = f = g

instance Stream d d (IO c) (IO c) where
f - g = g f

instance Stream d d c c where
x - y = y $ x

x - y = y $ x

-- This simply wraps a string in brackets.
bracket :: String - String
bracket x = ( ++ x ++ )

lbracket :: IO String - IO String
lbracket x = liftM bracket x

hello :: String
hello = Hello World!

lhello :: IO String
lhello = do return hello

main :: IO ()
main = do
   forkIO $ (bracket $ hello) - putStrLn
   forkIO $ lhello - lbracket - putStrLn
   forkIO $ bracket hello - putStrLn
   forkIO $ lbracket lhello - putStrLn
   threadDelay 1000 -- Sleep for at least 10 seconds before exiting.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Neil Brown

On 14/04/11 13:00, Chris Dew wrote:

class Stream a b c d where
 (-) :: a -  (b -  c) -  d

instance Stream (IO d) d (IO c) (IO c) where
 f -  g = f= g

instance Stream d d (IO c) (IO c) where
 f -  g = g f

instance Stream d d c c where
 x -  y = y $ x



I notice that in all your instances, the last two types are the same.  
So do you need the final type parameter?  Could you not make it:


class Stream a b c where
  (-) :: a - (b - c) - c

I quickly tried this, and it fixes the errors you were getting.  If that 
doesn't hold for all instances you have in mind, then you may want to 
use functional dependencies or type families to specify a relationship 
between the types.


Thanks,

Neil.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Stephen Tetley
Hi Chris

What does the Stream class *do* though?

class Stream a b c d where
(-) :: a -  (b -  c) -  d

Even with Neil's change its still quite unusual:

class Stream a b c where
 (-) :: a - (b - c) - c

In the first formulation there is an input of type a, a function (b -
c) and a result of a completely different type d.

In Neil's class the function relates to the type of the answer but not
to the input.

The difficult type classes in Haskell - Applicative, Monad, and
Arrows / Category - are related to some degree to fairly standard
combinators on functions. But they generalize the combinators to
operate on other types than the function type (-). As there isn't a
relation between input and output, I don't quite see how the Stream
type could start as a combinator.

Best wishes

Stephen

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Sebastian Fischer
Hi Dimitri,

 When asking how to implement cache in Haskell I was hopping that there
 exists some solution without using Data.Array, more functional approach,
 if I may say so  ...

Steven's second solution is purely functional. It uses so-called tries
to cache results instead of mutable arrays. Here is an alternative
definition of Steven's `fixmemo` function:

fixmemo :: HasTrie a = ((a - b) - (a - b)) - (a - b)
fixmemo f = fix (memo . f)

It uses the standard fixpoint combinator

Data.Function.fix :: (a - a) - a

and has a similar (but more restrictive) type. In order to understand
Steven's solution you need to know how to define recursive functions
using a fixpoint combinator. For example, you can define the Fibonacci
function as follows:

fibonacci :: Int - Integer
fibonacci = fix fib

fib :: (Int - Integer) - (Int - Integer)
fib fib 0 = 0
fib fib 1 = 1
fib fib n = fib (n-1) + fib (n-2)

Note how the first argument `fib` of the function `fib` shadows the
name of the global function `fib`.

The advantage of this complicated definition is that you get a
memoized version of the `fibonacci` function simply by using `fixmemo`
instead of `fix`:

memoFib :: Int - Integer
memoFib = fixmemo fib

This definition avoids to recompute the same recursive calls over and
over again in is therefore much faster than the original version.

That said, memoization helps to solve your original problem only if
you reuse the cache for different top-level calls of the Collatz
length function. According to the Collatz conjecture no argument
appears again when computing the Collatz length of a number (otherwise
the computation would not terminate).

Ryan's solution achieves reuse of the cache by defining it at the top
level and you can do the same with tries. For the `fib` example it
would look like this:

fibCache :: Int :-: Integer
fibCache = trie (fib cachedFib)

cachedFib :: Int - Integer
cachedFib = untrie fibCache

Now even independent calls to `cachedFib` reuse previously computed results.

In my experiments, caching did not pay off, even for computing the
maximum Collatz length of a given range. Without caching it took less
than 5 seconds to compute the maximum Collatz length of all numbers
between 1 and 100. With caching, it took 30 seconds.

Cheers,
Sebastian

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Munich functional programmers' UG

2011-04-14 Thread Dr. Heinrich Hördegen

 Dear all,

last week, there have been thoughts to create a user group for 
functional programmers in Munich, Germany. People who are interessted 
can join the new mailing list:


http://www.fs.lmu.de/cgi-bin/mailman/listinfo/high-order-munich

The idea is to have meetings every now and then with talks on aspects of 
functional programming. However, it's not restricted to Haskell. Please 
spread the word to anyone who could be interested.


Thank you,
Heinrich

--



hoerde...@funktional.info
www.funktional.info

--


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] parallel-haskell mailing list

2011-04-14 Thread Eric Y. Kow
Hi everybody,

I thought I should point out that there is a mailing list dedicated to
parallelism and concurrency in Haskell.  The group exists to bring
together the various groups in the Haskell community that are working on
parallelism. It is intended to provide some visibility into the various
efforts and to encourage collaboration.  So if you want to know what's
going on in the parallel Haskell world, this is the place to hang out.

You can join the list by sending an email to

   parallel-haskell+subscr...@googlegroups.com

You can also visit the group on the web at

   http://groups.google.com/group/parallel-haskell

Or for those of you who prefer GMane

   http://dir.gmane.org/gmane.comp.lang.haskell.parallel

Enjoy!

Eric

-- 
Got news for the Parallel Haskell Digest?
Send a mail to e...@well-typed.com!


pgp2azpIL6ffL.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Questioning seq

2011-04-14 Thread Andrew Coppin

A couple of questions:

1. Why is the existence of polymorphic seq bad?

2. Why would the existence of polymorphic rnf be worse?

3. How is pseq different from seq?

That is all...

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Luke Palmer
On Thu, Apr 14, 2011 at 4:29 AM, Dmitri O.Kondratiev doko...@gmail.comwrote:

 3n+1 is the first, warm-up problem at Programming Chalenges site:

 http://www.programming-challenges.com/pg.php?page=downloadproblemprobid=110101format=html

 (This problem illustrates Collatz conjecture:

 http://en.wikipedia.org/wiki/3n_%2B_1#Program_to_calculate_Collatz_sequences
 )

 As long as the judge on this site takes only C and Java solutions, I
 submitted in Java some add-hock code (see at the end of this message) where
 I used recursion and a cache of computed cycles. Judge accepted my code and
 measured  0.292 sec with best overall submissions of 0.008 sec to solve the
 problem.

 *** Question: I wonder how to implement cache for this problem in Haskell?
 At the moment, I am not so much interested in the speed of the code, as in
 nice implementation.


This is the exact problem data-memocombinators was written to solve.
http://hackage.haskell.org/packages/archive/data-memocombinators/0.4.1/doc/html/Data-MemoCombinators.html

For this problem, it is too slow to memoize everything; you have to use a
bounded memo table.  That's why I use a combinator-based memo approach as
opposed to the type-directed approach used in eg. MemoTrie.  The memo table
you need is something like

switch (10^6) integral id

Luke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Questioning seq

2011-04-14 Thread Janis Voigtländer

Am 14.04.2011 18:57:35 schrieb Andrew Coppinandrewcop...@btinternet.com:

A couple of questions:

1. Why is the existence of polymorphic seq bad?


See http://www.iai.uni-bonn.de/~jv/acta.pdf, Sections 1 and 2 and
pointers therein.

Also, numerous discussions on this list over the years.

Best,
Janis.


2. Why would the existence of polymorphic rnf be worse?

3. How is pseq different from seq?

That is all...




--
Jun.-Prof. Dr. Janis Voigtländer
http://www.iai.uni-bonn.de/~jv/
mailto:j...@iai.uni-bonn.de

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Questioning seq

2011-04-14 Thread austin seipp
As usual, I'm foolish and forget to hit 'reply to all'. Original
message unedited below, so it can be sent to -cafe.

To answer question #3, pseq and seq are semantically equivalent
(indeed, if you look at the source for Control.Parallel, if you are
not using GHC, pseq is defined as 'pseq = seq'.) There is a subtle
operational difference however: seq is strict in both of its
arguments, while pseq is only strict in its first argument as far as
GHC is concerned.

When you annotate code for parallelism, seq is a little more
problematic, because you want more control over the evaluation order.
For example, given a `seq` b, the compiler can freely rearrange this
in a number of ways - but if we are evaluating code in parallel,
that's a little too strict. So typically you want to say a `pseq` b -
you will strictly evaluate 'a' before 'b', presumably because 'b' has
already been sparked off in parallel using `par`. If you were using
seq, the compiler can rearrange a `seq` b into say, b `seq` a `seq` b.
Which won't gain you anything from a parallel perspective, for the
most part.

For more info, see the Control.Parallel module:

http://hackage.haskell.org/packages/archive/parallel/3.1.0.1/doc/html/Control-Parallel.html

Also see Simon  Simon's paper, 'Runtime support for Multicore
Haskell', particularly section 2, 'Background: programming model'.

http://community.haskell.org/~simonmar/papers/multicore-ghc.pdf

On Thu, Apr 14, 2011 at 12:57 PM, Andrew Coppin
andrewcop...@btinternet.com wrote:
 A couple of questions:

 1. Why is the existence of polymorphic seq bad?

 2. Why would the existence of polymorphic rnf be worse?

 3. How is pseq different from seq?

 That is all...

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Regards,
Austin

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Chris Dew
@Neil Brown - That did it.  It's not the ideal solution, as all -
are 'coerced' into being 'IO x' (if the rightmost term is an 'IO x'.
But it'll do for the time being.

Many thanks,

Chris.

On 14 April 2011 13:50, Neil Brown nc...@kent.ac.uk wrote:
 On 14/04/11 13:00, Chris Dew wrote:

 class Stream a b c d where
     (-) :: a -  (b -  c) -  d

 instance Stream (IO d) d (IO c) (IO c) where
     f -  g = f= g

 instance Stream d d (IO c) (IO c) where
     f -  g = g f

 instance Stream d d c c where
     x -  y = y $ x


 I notice that in all your instances, the last two types are the same.  So do
 you need the final type parameter?  Could you not make it:

 class Stream a b c where
  (-) :: a - (b - c) - c

 I quickly tried this, and it fixes the errors you were getting.  If that
 doesn't hold for all instances you have in mind, then you may want to use
 functional dependencies or type families to specify a relationship between
 the types.

 Thanks,

 Neil.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Chris Dew
@Stephen Tetley - The stream class exists simply to allow for the
creation of a - operator which can be used to 'Stream' data through
multiple pure and IO functions, on the way to some form of output.
It's probably not a great idea, as there are more idiomatic solutions
in Haskell - I'm sure someone will mention arrows.

I want the result of (-) to be what the following function requires,
either an 'a' or and 'IO a'.  This is too unconstrained if the
following function is flexible in it's input.  (e.g. another
application of (-)).   Hence my original problem.

a and b have are related, but not in a way I know how to express in
Haskell.  They are constrained to: a == b || IO a == b || a == IO b. c
and d have a similar constraint.

Could you suggest how these constraints could be expressed in the
Haskell type system?

Thanks,

Chris.

On 14 April 2011 14:28, Stephen Tetley stephen.tet...@gmail.com wrote:
 Hi Chris

 What does the Stream class *do* though?

 class Stream a b c d where
    (-) :: a -  (b -  c) -  d

 Even with Neil's change its still quite unusual:

 class Stream a b c where
  (-) :: a - (b - c) - c

 In the first formulation there is an input of type a, a function (b -
 c) and a result of a completely different type d.

 In Neil's class the function relates to the type of the answer but not
 to the input.

 The difficult type classes in Haskell - Applicative, Monad, and
 Arrows / Category - are related to some degree to fairly standard
 combinators on functions. But they generalize the combinators to
 operate on other types than the function type (-). As there isn't a
 relation between input and output, I don't quite see how the Stream
 type could start as a combinator.

 Best wishes

 Stephen

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Stephen Tetley
On 14 April 2011 20:35, Chris Dew cms...@gmail.com wrote:

 Could you suggest how these constraints could be expressed in the
 Haskell type system?


Hi Chris

I'm afriad I'd have to decline - generally in Haskell implicit
lifters are problematic, so it isn't something I'd be looking to
solve.


There was a thread on Haskell Cafe about them last November called
Making monadic code more concise, that you might find interesting -
especially Oleg Kiselyov's comments:

http://www.haskell.org/pipermail/haskell-cafe/2010-November/086445.html

Best wishes

Stephen

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?

2011-04-14 Thread Chris Dew
Thanks, that link's very relevant to what I'm trying.  For the time
being I'll accept a partial solution where the last two types are now
the same, and try to improve it when my knowledge of Haskell improves.

I really want (hello - bracket) in (hello - bracket -
putStrLn) to have a type of String.  Using the partial solution
which Neil Brown proposed, the code will work, but (hello -
bracket) will have a type of IO String which *seems* like it will be
less efficient.

All the best,

Chris.

On 14 April 2011 21:22, Stephen Tetley stephen.tet...@gmail.com wrote:
 On 14 April 2011 20:35, Chris Dew cms...@gmail.com wrote:

 Could you suggest how these constraints could be expressed in the
 Haskell type system?


 Hi Chris

 I'm afriad I'd have to decline - generally in Haskell implicit
 lifters are problematic, so it isn't something I'd be looking to
 solve.


 There was a thread on Haskell Cafe about them last November called
 Making monadic code more concise, that you might find interesting -
 especially Oleg Kiselyov's comments:

 http://www.haskell.org/pipermail/haskell-cafe/2010-November/086445.html

 Best wishes

 Stephen

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Questioning seq

2011-04-14 Thread Albert Y. C. Lai

On 11-04-14 01:57 PM, Andrew Coppin wrote:

3. How is pseq different from seq?


An example to show that there are non-unique evaluation orders to 
fulfill the mere strictness promise of seq:


import Data.List(foldl')
()  () = ()
main = print (foldl' () () (replicate 250 ()))

with ghc with -O0 : fast, no stack overflow
with ghc with -O or -O2: slow, stack overflow

ghc versions 6.12.3, 7.0.2, 7.0.3

Look at the core code (-ddump-simpl) to verify evaluation orders.

Repeat the experiment and observations with pseq:

import GHC.Conc(pseq)
()  () = ()
foldl' :: (a - b - a) - a - [b] - a
foldl' op z xs = go z xs where
  go z [] = z
  go z (x:xs) = let z' = op z x in z' `pseq` go z' xs
main = print (foldl' () () (replicate 250 ()))

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Experimental 64 bit installer fails

2011-04-14 Thread Andrew Pennebaker
I downloaded the experimental 64 bit installer for from Haskell
Platformhttp://hackage.haskell.org/platform/mac.html.
It fails with the message The installation failed.

In case Haskell Platform i386 was interfering, I uninstalled it. But the 64
bit installer still yields The installation failed.

Specs

   - Haskell Platform 2011.2.0.0-x86_64 installer
   - Haskell Platform 2011.2.0.0-i386 present
   - Mac OS X 10.6.7
   - MacBook Pro 5,1

/var/log/install.log

Apr 14 17:58:38 wonko Installer[18657]: Haskell Platform  Installation Log
Apr 14 17:58:38 wonko Installer[18657]: Opened from:
/Users/andrew/Downloads/Haskell Platform 2011.2.0.0-x86_64.pkg
Apr 14 17:58:46 wonko runner[18669]: Administrator authorization granted.
Apr 14 17:58:46 wonko Installer[18657]:

Apr 14 17:58:46 wonko Installer[18657]: User picked Standard Install
Apr 14 17:58:46 wonko Installer[18657]: Choices selected for installation:
Apr 14 17:58:46 wonko Installer[18657]: Upgrade: Haskell Platform
Apr 14 17:58:46 wonko Installer[18657]: Upgrade: Glasgow Haskell Compiler
Apr 14 17:58:46 wonko Installer[18657]: Haskell Platform
2011.2.0.0-x86_64.pkg#ghc.pkg : org.haskell.HaskellPlatform.GHC.pkg : 1
Apr 14 17:58:46 wonko Installer[18657]: Upgrade: Haskell Platform
Libraries
Apr 14 17:58:46 wonko Installer[18657]: Haskell Platform
2011.2.0.0-x86_64.pkg#haskell.pkg :
org.haskell.HaskellPlatform.Libraries.pkg : 1
Apr 14 17:58:46 wonko Installer[18657]: Haskell Platform
2011.2.0.0-x86_64.pkg#haskellPlatformPostflight.pkg :
org.haskell.haskellPlatform.postflight.pkg : 1.0
Apr 14 17:58:46 wonko Installer[18657]:

Apr 14 17:58:46 wonko Installer[18657]: It took 0.00 seconds to summarize
the package selections.
Apr 14 17:58:46 wonko Installer[18657]: -[IFDInstallController(Private)
_buildInstallPlan]: location = file://localhost
Apr 14 17:58:46 wonko Installer[18657]: -[IFDInstallController(Private)
_buildInstallPlan]:
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#ghc.pkg
Apr 14 17:58:46 wonko Installer[18657]: -[IFDInstallController(Private)
_buildInstallPlan]:
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#haskell.pkg
Apr 14 17:58:46 wonko Installer[18657]: -[IFDInstallController(Private)
_buildInstallPlan]:
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#haskellPlatformPostflight.pkg
Apr 14 17:58:46 wonko Installer[18657]: Will use PK session
Apr 14 17:58:46 wonko Installer[18657]: Starting installation:
Apr 14 17:58:46 wonko Installer[18657]: Configuring volume Wonko
Apr 14 17:58:46 wonko Installer[18657]: Preparing disk for local booted
install.
Apr 14 17:58:46 wonko Installer[18657]: Free space on Wonko: 52.51 GB
(52508946432 bytes).
Apr 14 17:58:46 wonko Installer[18657]: Create temporary directory
/var/folders/N-/N-IxaaKuFae5ik1WKxV6wE+++TI/-Tmp-//Install.18657bWOdda
Apr 14 17:58:46 wonko Installer[18657]: IFPKInstallElement (3 packages)
Apr 14 17:58:46 wonko installd[18673]: PackageKit: - Begin install -
Apr 14 17:58:46 wonko installd[18673]: PackageKit: request=PKInstallRequest
3 packages, destination=/
Apr 14 17:58:46 wonko installd[18673]: PackageKit: packages=(\n
 PKLeopardPackage
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#ghc.pkg,\n
   PKLeopardPackage
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#haskell.pkg,\n
   PKLeopardPackage
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#haskellPlatformPostflight.pkg\n)
Apr 14 17:58:47 wonko installd[18673]: PackageKit: Extracting
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#ghc.pkg
(destination=/var/folders/zz/zzzivhrRnAmviuee+++/Cleanup At
Startup/PKInstallSandbox-tmp/Root/Library/Frameworks, uid=0)
Apr 14 17:59:06 wonko installd[18673]: PackageKit: Extracting
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#haskell.pkg
(destination=/var/folders/zz/zzzivhrRnAmviuee+++/Cleanup At
Startup/PKInstallSandbox-tmp/Root/Library, uid=0)
Apr 14 17:59:12 wonko installd[18673]: PackageKit: Extracting
file://localhost/Users/andrew/Downloads/Haskell%20Platform%202011.2.0.0-x86_64.pkg#haskellPlatformPostflight.pkg
(destination=/var/folders/zz/zzzivhrRnAmviuee+++/Cleanup At
Startup/PKInstallSandbox-tmp/Root, uid=0)
Apr 14 17:59:14 wonko installd[18673]: PackageKit: Shoving
/var/folders/zz/zzzivhrRnAmviuee+++/Cleanup At
Startup/PKInstallSandbox-tmp/Root (1 items) to /
Apr 14 17:59:16 wonko installd[18673]: PackageKit: Executing script
./postinstall in
/private/tmp/PKInstallSandbox.e59JtF/Scripts/org.haskell.HaskellPlatform.GHC.pkg.k6SuIR
Apr 14 17:59:16 wonko installd[18673]: PackageKit: Executing script
./postinstall in

[Haskell-cafe] ghc7 bug? associated type + implicit parameters

2011-04-14 Thread Michal Konečný
Hi,

I have stumbled across some strange behaviour in ghc7.

The following compiles fine with ghc 6.12.3:

{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoMonomorphismRestriction #-}

module Test where

class C t where
type TF t
ttt :: TF t - t

b :: (C t, ?x :: TF t) = t
b = ttt ?x 

but ghc7 says:

Could not deduce (?x::TF t)
  arising from a use of implicit parameter `?x'
from the context (C t, ?x::TF t)
  bound by the type signature for b :: (C t, ?x::TF t) = t
  at Test.hs:13:1-10
In the first argument of `ttt', namely `?x'
In the expression: ttt ?x
In an equation for `b': b = ttt ?x

Moreover, when I comment out the type declaration for b, it compiles and the 
inferred type for b is identical to the one in the above program:

*Test :t b
b :: (C t, ?x::TF t) = t

It feels to me like a bug but I am not entirely confident.  Any ideas?

Michal
-- 
|o| Michal Konecny mikkone...@gmail.com
|o|http://www-users.aston.ac.uk/~konecnym/
|o|office: (+42) (0)121 204 3462 
|o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

-- 
|o| Michal Konecny mikkone...@gmail.com
|o|http://www-users.aston.ac.uk/~konecnym/
|o|office: (+42) (0)121 204 3462 
|o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

-- 
|o| Michal Konecny mikkone...@gmail.com
|o|http://www-users.aston.ac.uk/~konecnym/
|o|office: (+42) (0)121 204 3462 
|o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston


signature.asc
Description: This is a digitally signed message part.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Experimental 64 bit installer fails

2011-04-14 Thread Mark Lentczner
Well that's no fun! The install looks like it mostly worked, execept that
the final registration of the installed packages failed because for some
reason the script has them out of order.

You can fix up your install by doing this:

cd /Library/Haskell/ghc-7.0.2/lib/registrations
for c in *.conf; do echo == $c ==; ghc-pkg register --force $c; done


I'll have to look into why that build of the package got the files out of
order...
 - Mark
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Experimental 64 bit installer fails

2011-04-14 Thread Andrew Pennebaker
I can confirm that Mark's Haskell 2011.2.0.0-x86_64 Mac OS X installer fix
works :)

cd /Library/Haskell/ghc-7.0.2/lib/registrations
for c in *.conf; do echo == $c ==; ghc-pkg register --force $c; done


My goal is to get Haskell ncurses working. c2hs is required, so I did:

$ cabal --version
cabal-install version 0.10.2
using version 1.10.1.0 of the Cabal library

$ cabal install c2hs
$ c2hs
-bash: c2hs: command not found

It appears Cabal never added ~/Library/Haskell/ghc-7.0.2/lib/c2hs-0.16.3/bin
to PATH. It's easy enough for me personally to fix, but Haskell 2010 didn't
have this problem.

Cheers,

Andrew Pennebaker
www.yellosoft.us

On Thu, Apr 14, 2011 at 7:28 PM, Mark Lentczner mark.lentcz...@gmail.com
wrote:

 Well that's no fun! The install looks like it mostly worked, execept that
 the final registration of the installed packages failed because for some
 reason the script has them out of order.

 You can fix up your install by doing this:

 cd /Library/Haskell/ghc-7.0.2/lib/registrations
 for c in *.conf; do echo == $c ==; ghc-pkg register --force $c; done


 I'll have to look into why that build of the package got the files out of
 order...
  - Mark

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghc7 bug? associated type + implicit parameters

2011-04-14 Thread Antoine Latter
Someone on the ghc-users list might have an idea. I recommend filing a
bug report:

http://hackage.haskell.org/trac/ghc/wiki/ReportABug

Even if the behavior isn't wrong, in could use a better error message!

Antoine

2011/4/14 Michal Konečný mikkone...@googlemail.com:
 Hi,

 I have stumbled across some strange behaviour in ghc7.

 The following compiles fine with ghc 6.12.3:

 {-# LANGUAGE ImplicitParams #-}
 {-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE NoMonomorphismRestriction #-}

 module Test where

 class C t where
    type TF t
    ttt :: TF t - t

 b :: (C t, ?x :: TF t) = t
 b = ttt ?x

 but ghc7 says:

    Could not deduce (?x::TF t)
      arising from a use of implicit parameter `?x'
    from the context (C t, ?x::TF t)
      bound by the type signature for b :: (C t, ?x::TF t) = t
      at Test.hs:13:1-10
    In the first argument of `ttt', namely `?x'
    In the expression: ttt ?x
    In an equation for `b': b = ttt ?x

 Moreover, when I comment out the type declaration for b, it compiles and the
 inferred type for b is identical to the one in the above program:

 *Test :t b
 b :: (C t, ?x::TF t) = t

 It feels to me like a bug but I am not entirely confident.  Any ideas?

 Michal
 --
 |o| Michal Konecny mikkone...@gmail.com
 |o|    http://www-users.aston.ac.uk/~konecnym/
 |o|    office: (+42) (0)121 204 3462
 |o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

 --
 |o| Michal Konecny mikkone...@gmail.com
 |o|    http://www-users.aston.ac.uk/~konecnym/
 |o|    office: (+42) (0)121 204 3462
 |o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

 --
 |o| Michal Konecny mikkone...@gmail.com
 |o|    http://www-users.aston.ac.uk/~konecnym/
 |o|    office: (+42) (0)121 204 3462
 |o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aston

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Programming Chalenges: The 3n+1 problem

2011-04-14 Thread Eduard Sergeev
Hi Dmitri,

 *** Question: I wonder how to implement cache for this problem in Haskell?
 At the moment, I am not so much interested in the speed of the code, as in
 nice implementation.

Yet another option for memoization implementation: to use monad-memo
package [1] which provides memoization for monadic function (using
Data.Map by default).

To use it we need to define our recursive function in monadic form and
add `memo` in place of its recursive call:

 import Control.Applicative
 import Control.Monad.Memo

 -- calculates the length of sequence (with memoization)
 calcM 1 = return 1
 calcM n = succ $ memo calcM (if even n then n `div` 2 else n*3 + 1)

Here is a helper-function to run this calculation (we don't really
need it here since `calcM` is going to be called from other monadic
function directly):

 runCalc :: Integer - Integer
 runCalc = startEvalMemo . calcM

NB: the inferred type for `calcM` might look a little bit.. verbose,
but we don't really need to specify it or expose `calcM` from our
module:
 calcM :: (MonadMemo a1 a m, Num a, Functor m, Integral a1, Enum a) = a1 - m 
 a


The implementation of the function to calculate the maximum length of
the sequence for all numbers in a range is straightforward (and also
monadic):

 -- NB: memoization cache is shared among all 'calcM' calls (very efficient)
 calcRangeM f t = maximum $ forM [f..t] calcM

and a similar helper run-function (is not needed for the task either):

 runCalcRange :: Integer - Integer - Integer
 runCalcRange f t = startEvalMemo $ calcRangeM f t


To run `calcRangeM` for the input list of values (map the function
over it) we can define yet another simple monadic function which calls
`calcRangeM` directly (thus reusing/building the same memoization
cache):

 solM = mapM (uncurry calcRangeM)

and a helper run-function:

 runSol :: [(Integer, Integer)] - [Integer]
 runSol = startEvalMemo . solM


Composing all these together results in the following test code (I
hard-coded the input for the sake of simplicity):

 import Control.Applicative
 import Control.Monad.Memo

 calcM 1 = return 1
 calcM n = succ $ memo calcM (if even n then n `div` 2 else n*3 + 1)

 calcRangeM f t = maximum $ forM [f..t] calcM

 solM = mapM (uncurry calcRangeM)

 runSol = startEvalMemo . solM

 main = print $ runSol [
(1, 10),
(100, 200),
(201, 210),
(900, 1000) ]


As for the performance, `main = print $ runSol [(1, 100)]` takes
~40 seconds with -O2 on my laptop.


[1] http://hackage.haskell.org/package/monad-memo

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem building qtHaskell

2011-04-14 Thread Øystein Kolsrud
Thanks for the tip! I reinstalled everything from scratch here, and
then I got it working.

On Wed, Apr 13, 2011 at 2:26 AM, Mark Wright
markwri...@internode.on.net wrote:
 On Tue, 12 Apr 2011 12:14:50 +0200, Øystein Kolsrud kols...@gmail.com wrote:
 Hi! I am trying to install qtHaskell on a Windows 7 machine, but I am
 running into some problems while running the build script. I believe I
 have followed all the steps stated in the installation instructions,
 but get errors of this type:

 Creating library file: ..\bin\libqtc_core.a
 c:\Prog\Qt\2010.05\qt\lib/libQtUiTools.a(quiloader.o):quiloader.cpp:(.text+0x3c3):
 undefined reference to `_Unwind_Resume'

 Hi Øystein,

 Maybe this might give some hints:

 http://www.qtcentre.org/threads/33394-Link-errors-undefined-reference-to-_Unwind_Resume-and-__gxx_personality_v0

 It suggests checking if c:\Prog\Qt\2010.05\qt\lib/libQtUiTools.a was
 built with the same g++ version.

 Regards, Mark

 Can anyone help me figure out what is missing? I have the following
 versions installed which should meet the requirements:

 C:\Prog\QTHASK~1.4g++ --version
 g++ (GCC) 4.4.3

 C:\Prog\QTHASK~1.4gmake --version
 GNU Make 3.81
 This program built for Windows32

 C:\Prog\QTHASK~1.4ghc --version
 The Glorious Glasgow Haskell Compilation System, version 7.0.2

 Thanks!

 Best regards, Øystein Kolsrud

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Mvh Øystein Kolsrud

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe