Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-28 Thread Hans Aberg


On 28 Mar 2008, at 03:03, Ryan Ingram wrote:
Another way to defer the evaluation of the second argument of (-+)  
is like this:


(-+) :: a -> List a -> List a
x -+ y = List(f) where
  f 0 = x
  f k = case y of List g -> g (k-1)

This is exactly what the lazy pattern will do at compile-time.


Thank you for inputs - I discovered adding ordinal length made it  
tricky to get the lazy evaluation I called for. The problem is that I  
use

  data List a = (Ordinal->a) :+ Ordinal
and then in
  (-++) :: a -> List a -> List a
  x -++ (b:+ q) = f:+(1+q) where
f 0 = x
f k = b(k-1)
possibly I need to get both b and q to be lazy. I tried experimenting  
with putting i ~also on them, but it did not seem to work.


So I may have to experiment a bit more, and perhaps return with a  
more completet example later. But inputs are welcome.



Does
this give you a better understanding of how lazy patterns work and why
they fix the problem?


I had such rewriting in mind as well, but could not figure out the  
right blend. The manual call the lazy pattern "irrefutable". The  
terminology you use here is more intuitive.


It show a problem in language design: Haskell has mad a choice of  
strict and lazy evaluation in different context, but it has the  
disadvantage of hiding away the semantics. Something to think about  
when designing the next lazy computer language. :-)


  Hans Aberg


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


RE: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Paul Keir
Thanks, I'd thought it was something to do with incompatible types. I can now 
create a simpler problem:

tester2 = reserved "parameter" <|> symbol ":"

Certainly I could use reserved ":" instead of symbol, but where is my thinking 
with symbol here going wrong? Surely the above example isn't so odd?

Paul


-Original Message-
From: Luke Palmer [mailto:[EMAIL PROTECTED]
Sent: Fri 3/28/2008 12:26 AM
To: Paul Keir
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Parsec Expected Type
 
Hi Paul,

2008/3/27 Paul Keir <[EMAIL PROTECTED]>:
> Hi,
>
>  Does anyone know why this reduced Parsec production stops compilation, and
> how I can fix it?
>
>  tester = reserved "parameter"
>   <|> do { reserved "dimension"; symbol ":" }

Look at the types of "reserved" and "symbol" (from
http://www.haskell.org/ghc/docs/latest/html/libraries/parsec/Text-ParserCombinators-Parsec-Token.html):

  symbol :: String -> CharParser st String
  reserved :: String -> CharParser st ()

The type of a do block is the same as the type of its last statement.
But (reserved "parameter") and (symbol ";") do not have the same type.

Luke

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


Re: [Haskell-cafe] Unescaping with HaXmL (or anything else!)

2008-03-28 Thread Henning Thielemann


On Thu, 27 Mar 2008, Anton van Straaten wrote:

I want to unescape an encoded XML or HTML string, e.g. converting " to 
the quote character, etc.


Since I'm using HaXml anyway, I tried using xmlUnEscapeContent with no luck, 
e.g. with HaXml 1.19.1:


let (CString _ s _) =
 head $ xmlUnEscapeContent stdXmlEscaper $
  [CString  False "This is a "quoted string"" ()] in s

The result is unchanged, i.e. "This is a "quoted string"".

Am I doing something wrong, or are my expectations wrong, or is this a bug?

Or, is there any other library that includes a simple unescape function for 
XML or HTML?


Tagsoup must contain such a function but it doesn't seem to export it.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] compilation succeeds -- execution fails

2008-03-28 Thread Jason Dusek
  I have a program here:

https://svn.j-s-n.org/public/haskell/cedict

  currently at revision 302, which compiles okay but I can't get
  it to work. I'm using the FFI to take a (currently small)
  array and translate it into a Map.

  It compiles fine and loads fine -- but it doesn't run fine:

GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> import Data.Char.CEDICT
Prelude Data.Char.CEDICT> traditional 'a'
Loading package array-0.1.0.0 ... linking ... done.
Loading package containers-0.1.0.1 ... linking ... done.
Loading package parsec-2.1.0.0 ... linking ... done.
Loading package utf8-string-0.2 ... linking ... done.
Loading package cedict-0.1.1 ... linking ... :
unknown symbol `___stginit_cedictzm0zi1zi1_DataziCharziCEDICTziMatter_'
ghc-6.8.2: unable to load package `cedict-0.1.1'
Prelude Data.Char.CEDICT>

  I'm on a Mac -- Leopard. A whole bunch of things *could* be
  wrong -- I'd appreciate some help in narrowing the list.

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


Re: [Haskell-cafe] compilation succeeds -- execution fails

2008-03-28 Thread Thomas Schilling

Did you try removing all .hi and .o files?

On 28 mar 2008, at 10.34, Jason Dusek wrote:


  I have a program here:

https://svn.j-s-n.org/public/haskell/cedict

  currently at revision 302, which compiles okay but I can't get
  it to work. I'm using the FFI to take a (currently small)
  array and translate it into a Map.

  It compiles fine and loads fine -- but it doesn't run fine:

GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> import Data.Char.CEDICT
Prelude Data.Char.CEDICT> traditional 'a'
Loading package array-0.1.0.0 ... linking ... done.
Loading package containers-0.1.0.1 ... linking ... done.
Loading package parsec-2.1.0.0 ... linking ... done.
Loading package utf8-string-0.2 ... linking ... done.
Loading package cedict-0.1.1 ... linking ... :
unknown symbol  
`___stginit_cedictzm0zi1zi1_DataziCharziCEDICTziMatter_'

ghc-6.8.2: unable to load package `cedict-0.1.1'
Prelude Data.Char.CEDICT>

  I'm on a Mac -- Leopard. A whole bunch of things *could* be
  wrong -- I'd appreciate some help in narrowing the list.

--
_jsn
___
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] Functional dependencies with Type Classes

2008-03-28 Thread Wolfgang Jeltsch
Am Freitag, 28. März 2008 02:12 schrieb Henning Günther:
> Hi,
>
> suppose there are two (identical) classes:
> > class Res a b | a -> b  where
> > getRes :: a -> b
>
> and
>
> > class Res2 t where
> > type Member t
> > getRes2 :: t -> Member t
>
> It is easy to automatically make every instance of Res2 an instance of
>
> res:
> > instance Res2 a => Res a (Member a) where
> > getRes x = getRes2 x
>
> However, declaring every instance of Res an instance of Res2 seems
> impossible, as the following doesn't compile
>
> > instance Res a b => Res2 a where
> > type Member a = b
> > getRes2 x = getRes x
>
> Question is: How to do this? The reason I need it is because I use a
> library which uses functional dependencies, but my classes shall be type
> families.
>
> Regards,
> Henning

Hello Henning,

I also came across this problem half a year ago, tried to find a solution and 
came to the conclusion that there is none.  It seems as if functional 
dependencies are a trap: Once you’ve started using them it is impossible to 
escape them by switching to type families.  So you’ll probably have your own 
code use functional dependencies too (This was the “solution” I used in my 
case.) or you have to rewrite the library to use type families.

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


Re: [Haskell-cafe] Wumpus World

2008-03-28 Thread Benjamin L. Russell

--- "Richard A. O'Keefe" <[EMAIL PROTECTED]> wrote:

> [snip]
> 
> The Prolog results at
> http://shootout.alioth.debian.org/
> are only for the open source system SWI Prolog,
> which is basically
> a one-man effort.  The commercial SICStus Prolog is
> substantially
> faster.  Some of the Prolog benchmark versions look
> distinctly odd.

The commercial SICStus Prolog is also substantially
more expensive (see
http://www.sics.se/isl/sicstuswww/site/index.html), at
153 euros for a Personal License (see
http://www.sics.se/isl/sicstuswww/site/order4.html). 
Prices for Academic, Single-User Commercial, and
Multi-User Commercial licenses are even more
expensive, at 1560, 1980, and 7800 euros,
respectively.  An Evaluation License is only valid for
30 days.

Not all students and researchers can afford a Personal
License.  Can you recommend an alternative, fast
Prolog development system under a free licensing
agreement, such as GPL/GLPL?

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


Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-28 Thread Hans Aberg

On 28 Mar 2008, at 03:03, Ryan Ingram wrote:

Another way to defer the evaluation of the second argument of (-+)  
is like this:


(-+) :: a -> List a -> List a
x -+ y = List(f) where
  f 0 = x
  f k = case y of List g -> g (k-1)

This is exactly what the lazy pattern will do at compile-time.  Does
this give you a better understanding of how lazy patterns work and why
they fix the problem?



I have various other patterns that need to be forced lazy - inputs  
welcome. In the code below, where I have put in a "0" instead of the  
first uncountable ordinal w, if I include in "show" the case a == 0,  
then

  h (list 6)
won't print, as then the value of "a" is computed.

And in the ordinal version
  data List a = (Ordinal->a) :+ Ordinal
then the function
  (-+) :: a -> List a -> List a
  x -+ ~(y :+ q) = f:+(1+q) where
f 0 = x
f k = y(k-1)
does not compute, because there is a similar problem with the 1+q  
evaluation, I think this is because the class Ordinal + uses case:

  instance Num Ordinal where
x + y | finite x && finite y = toOrdinal(tcoef x + tcoef y)
x + y | lexp x < lexp y  = y
x + y | lexp x == lexp y = prepend (lexp x, lcoef x + lcoef y)  
(trail y)

x + y = prepend (lexp x, lcoef x) ((trail x) + y)
So these patterns perhaps should be made lazy. though I do not know  
exactly how.


  Hans



infixr 5  :+

data List a = (Integer->a) :+ Integer

instance Show a => Show (List a) where
--  show (f:+a) | a == 0 = "[]"
  show (f :+ a) = "[" ++ show (f(0)) ++
concat ["," ++ show (f(toInteger i))| i<-[1..]] ++ "]"

list :: Integer -> List Integer
list x = (\z -> x+z) :+ 0

(-+) :: a -> List a -> List a
x -+ ~(y :+ q) = f:+(1+q) where
  f 0 = x
  f k = y(k-1)

first :: List a -> a
first (f :+ _) = f 0

rest :: List a -> List a
rest (y :+ _) = f :+ 0 where
  f k = y(k+1)

h :: List a -> List a
h x = (-+) (first x) (h (rest x))


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


Re: [Haskell-cafe] Wumpus World

2008-03-28 Thread Andrew Butterfield

Benjamin L. Russell wrote:



Not all students and researchers can afford a Personal
License.  Can you recommend an alternative, fast
Prolog development system under a free licensing
agreement, such as GPL/GLPL?
  


For Mac users, https://www.cs.tcd.ie/open-prolog/ might be worth a look
  


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


Re: [Haskell-cafe] Wumpus World

2008-03-28 Thread jerzy . karczmarczuk



Benjamin L. Russell wrote:
 


Not all students and researchers can afford a Personal
License.  Can you recommend an alternative, fast
Prolog development system under a free licensing
agreement, such as GPL/GLPL?


You have quite a choice if you relax your licensing requirements: 

http://www.thefreecountry.com/compilers/prolog.shtml 


You will find there the GNU-Prolog, whose licensing should be as
you wish. 

Jerzy Karczmarczuk 



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


Re: [Haskell-cafe] Sound typeable via type families?

2008-03-28 Thread Wolfgang Jeltsch
Am Freitag, 28. März 2008 05:21 schrieb Dan Doel:
> […]

> However, obviously, this depends on overlapping instances (if there's some
> other way, I'd be happy to know; if type inequality contexts are available,
> I wasn't able to find them), and I've heard that type families don't play
> well with overlap. Does that not apply to data families? Will this
> construction still work in 6.10 and beyond?
>
> Also, this doesn't seem to be a suitable basis for Dynamic. Trying to
> extend the GADT solution presented resulted in errors unless incoherent
> instances were turned on (clearly not a good sign), and even then, it
> didn't actually work. Is it possible to do better, and come away with
> something that will actually work for Dynamic, and be sound?

I don’t know exactly whether this helps here but with open type families you 
will be able to define a type-level type equality decision.  See the mail at 
.

> […]

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


Re: [Haskell-cafe] Wumpus World

2008-03-28 Thread Tom Schrijvers

Not all students and researchers can afford a Personal
License.  Can you recommend an alternative, fast
Prolog development system under a free licensing
agreement, such as GPL/GLPL?


SWI-Prolog is about the best and most popular open Prolog system:

http://www.swi-prolog.org

It's not the fastest, just like GCC doesn't generates the fastest code. 
Who cares?


If you want speed, then Yap is the best open Prolog system.

http://www.ncc.up.pt/~vsc/Yap/

Cheers,

Tom

--
Tom Schrijvers

Department of Computer Science
K.U. Leuven
Celestijnenlaan 200A
B-3001 Heverlee
Belgium

tel: +32 16 327544
e-mail: [EMAIL PROTECTED]
url: http://www.cs.kuleuven.be/~toms/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-28 Thread Hans Aberg

On 28 Mar 2008, at 03:03, Ryan Ingram wrote:
Another way to defer the evaluation of the second argument of (-+)  
is like this:


(-+) :: a -> List a -> List a
x -+ y = List(f) where
  f 0 = x
  f k = case y of List g -> g (k-1)

This is exactly what the lazy pattern will do at compile-time.  Does
this give you a better understanding of how lazy patterns work and why
they fix the problem?


I can isolate the problem with the addition in the code below, where  
I have defined a type Natural just in order to introduce a user  
defined operator. - For ordinals, it is more complicated. Then

  h (list 6)
only printouts "[N 6,", after which it gets stuck in the Natural.+.  
Adding ~ to

  (N x) + (N y)
does not help, nor other variations. But replacing Natural with  
integer, produces the normal infinite list printout. So it must be  
here it is stuck.


  Hans



infix 5  :+

data Natural = N Integer
  deriving (Eq, Show)

instance Num Natural where
  fromInteger x = N x
  abs x = x
  signum 0 = 0
  signum _ = 1
  (N x) + (N y) = N(x + y)


data List a = (Natural->a) :+ Natural

instance Show a => Show (List a) where
  show (f :+ _) = "[" ++ show (f(0)) ++
concat ["," ++ show (f(N (toInteger i)))| i<-[1..]] ++ "]"

list :: Natural -> List Natural
list x = (\z -> x+z) :+ 0

(-+) :: a -> List a -> List a
x -+ ~(y :+ q) = f:+(1+q) where
  f 0 = x
  f k = y(k-1)

first :: List a -> a
first (f :+ _) = f 0

rest :: List a -> List a
rest (y :+ _) = f :+ 0 where
  f k = y(k+1)

h :: List a -> List a
h x = (-+) (first x) (h (rest x))


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


Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-28 Thread Hans Aberg
I have fixed the problem now. In the last letter, with the Natural  
class, I had not added

  instance Num Natural where
(N x) - (N y) = N(x - y)
which the Ordinal class then in fact has one. Then it turns out that  
it is merely the fact that "show" had some cases looking at the list  
length that blocked its output. So there, one should probably have  
some recursion that extracts elements one by one, without computing  
list length, and adds a termination 2]" if the remaining list is empty.


So it seems possible to emulate Haskell list behavior with this  
model, which is one thing I wanted to know.


  Hans


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


Re: [Haskell-cafe] Monad instance for Data.Set, again

2008-03-28 Thread Henning Thielemann


On Fri, 28 Mar 2008, Wolfgang Jeltsch wrote:

But it is possible to give a construction of an Ord dictionary from an 
AssociatedMonad dictionary.  See the attached code.  It works like a 
charm. :-)


Yeah, type families! In which GHC release they will be included?

 Sometimes I wonder how many single type extensions we will see in future 
or whether there will be one mechanism which subsumes all existing ones in 
a simple manner. (Full logic programming on type level? Manual 
determination of the class dictionary to be used?)

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


Re: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Jonathan Cast

On 28 Mar 2008, at 2:02 AM, Paul Keir wrote:

Thanks, I'd thought it was something to do with incompatible types.  
I can now create a simpler problem:


tester2 = reserved "parameter" <|> symbol ":"

Certainly I could use reserved ":" instead of symbol, but where is  
my thinking with symbol here going wrong? Surely the above example  
isn't so odd?



What type do you expect tester2 to return?

jcc

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


[Haskell-cafe] Re: HTTP client libraries

2008-03-28 Thread John Goerzen
On 2008-03-28, Don Stewart <[EMAIL PROTECTED]> wrote:
> paulrbrown+haskell-cafe:
> And we have a curl binding, already in wide use.
>
> http://code.haskell.org/curl.git/
>
> a release to hackage is imminent.

Do you mean this?

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/curl-1.3.1

Looks like it's not quite as current as your Git repo.

-- John

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


[Haskell-cafe] Re: HTTP client libraries

2008-03-28 Thread John Goerzen
On 2008-03-27, Adam Langley <[EMAIL PROTECTED]> wrote:
> On Thu, Mar 27, 2008 at 12:08 PM, John Goerzen <[EMAIL PROTECTED]> wrote:
>>  * network-minihttp
>>
>>   Doesn't appear to actually be very useful as a client.
>>
>>  Also, as far as I have been able to deduce, none of these have
>>  built-in support for https (SSL) URLs.
>
> The client doesn't do a lot, but I don't know what you would want from
> a client. Email me a list of use cases and ;)

You know, it actually looks very nice to me.  I don't know what I was
looking at before, but I've poked around at your sources a bit and I
like what I see.  The fact that I can get a result as a lazy
ByteString is nice.  Your Source type is an interesting approach, too.

-- John


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


Re: [Haskell-cafe] Glome raytracer bug: bad output with -O2 -fasm

2008-03-28 Thread Luke Palmer
On Fri, Mar 28, 2008 at 6:28 AM, Jim Snow <[EMAIL PROTECTED]> wrote:
> I was trying to get Blinn highlights working with my raytracer, and kept
>  getting ugly artifacts.  After trying a bunch of things, I finally
>  compiled without -O2, and the artifacts went away.
>
>  Here's what I mean:
>  http://syn.cs.pdx.edu/~jsnow/glome/Glome.hs-noartifact.png
>  http://syn.cs.pdx.edu/~jsnow/glome/Glome.hs-artifact.png
>
>  Here's the offending code, run "./make" and "./run" and you should see
>  the artifacts if your setup is the same as mine. (Requires OpenGL.)
>  http://syn.cs.pdx.edu/~jsnow/glome/glome.hs-0.2-bug.tar.gz
>
>  The artifacts also go away if I use -fvia-C.  It doesn't seem to matter
>  whether I use Floats or Doubles in the rendering code.  The artifacts
>  also show up with -O1.  Have I stumbled across a known compiler bug?  Or
>  perhaps an OpenGL bug?  (The bug could, of course, be in my code, but
>  then one might expect to get the same erroneous output every time
>  regardless of compiler flags.)
>
>  To reiterate, I'm using ghc 8.6.2.

You probably mean 6.8.2.

Works for me in all cases.

% uname -a
Linux madhatter 2.6.22-gentoo-r8 #6 PREEMPT Sat Oct 20 04:19:22 GMT
2007 i686 AMD Turion(tm) 64 Mobile Technology ML-40 AuthenticAMD
GNU/Linux
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.2

Looks to me like Glome is depending on some very fine details of
floating point arithmetic.

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


Re: [Haskell-cafe] Web server libraries

2008-03-28 Thread Sterling Clover
Yipe. It's just been pointed out to me that the hvac repo was missing a key
file. I just committed it and tried a fresh pull and build, and it seems to
work properly now. Apologies to all who couldn't get it working.

Regards,
Sterl.

On Fri, 28 Mar 2008, Sterling Clover wrote:

> While hvac, which I announced here recently, is not yet ready for
> primetime, so to speak, you may want to take a look at it -- with a
> few tweaks it should match your specs. (darcs get http://
> community.haskell.org/~sclv/hvac/
)
>

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


Re: [Haskell-cafe] Re: SoC project: Python-Haskell bridge - request for feedback

2008-03-28 Thread Michał Janeczek
On Thu, Mar 27, 2008 at 8:27 PM, John Goerzen <[EMAIL PROTECTED]> wrote:
> FWIW, my MissingPy project accomplishes part of this (calling Python
>  from Haskell) already.
>
>  -- John

Yes, MissingPy was mentioned in the original project description,
and I have hopes of reusing substantial parts of it.
I'd like to make it more comprehensive (in particular, have it
support higher order functions when calling Python code),
and possibly also easier/more transparent to use.
And there of course comes the second side of the project,
calling Haskell from Python


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


Re: [Haskell-cafe] MonadMemory class

2008-03-28 Thread Mads Lindstrøm
Hi

Ariel J. Birnbaum wrote:
> Two questions came to mind while thinking of memory references in Haskell:
> 
> 1. Is there a "standard" equivalent of the following:
> 
> class (Monad m) => MonadMemory m r | m -> r where
> new :: a -> m (r a)
> read :: r a -> m a
> write :: r a -> a -> m ()

I do not think you can call it standard, but TypeCompose
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/TypeCompose-0.5 do 
implement Data.RefMonad, which does what you are describing.


Greetings,

Mads Lindstrøm


> 
> What kind of axioms should an instance of this class satisfy?
> 
> 2. How would a "pure" instance of this class look like (obvious 
> unsafePerformIO-based solutions aside)? Is it even possible in pure Haskell?
> 
> Thanks much!


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


Re: [Haskell-cafe] compilation succeeds -- execution fails

2008-03-28 Thread Jason Dusek
Thomas Schilling <[EMAIL PROTECTED]> wrote:
> Did you try removing all .hi and .o files?

  Yes. I tried it again this morning, and I've got the same
  error -- same unknown symbol, &c.

  I don't have trouble with most Haskell programs on my Mac, so
  I assume it's the way I'm connecting to C that is the problem.
  I've pasted in the relevant code below my signature -- it
  seems plain enough to me, but I've not done much with foreign
  declarations.

  The `Ptr Char` declarations, for example, point to things
  which are actually C ints -- they are all valid Unicode code
  points, so I figure there's no harm done.

-- 
_jsn

module Data.Char.CEDICT.Lists where

import Foreign
import Foreign.C
import Foreign.Storable
import Foreign.Marshal.Array

{-# INCLUDE "c/data.h" #-}

foreign import ccall unsafe "&" ts :: Ptr Char
foreign import ccall unsafe "&" ts_len :: Ptr Int
forTradSimp  =  pairUp $ readIn ts_len ts

foreign import ccall unsafe "&" st :: Ptr Char
foreign import ccall unsafe "&" st_len :: Ptr Int
forSimpTrad  =  pairUp $ readIn st_len st

readIn lenPtr arrPtr =  unsafePerformIO $ peekArray len arrPtr
 where
  len=  unsafePerformIO $ peek lenPtr

pairUp []=  []
pairUp [item]=  []
pairUp (a:b:rest)=  (a, b):(pairUp rest)

forLookup =
  [ ("\64013",[("huo4","to vomit")])
  , ("\64012",[("wu4","duplicate of Big Five A461")])
  , ("\40868",[("xie2","to harmonize / to accord with / to agree")])
  , ("\40866",[("he2","harmonious")])
  ]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [GSoC] Parallel Benchmarking and Profiling

2008-03-28 Thread Don Stewart
etienne:
> Hello,
> 
> I am putting together a student proposal to participate in Google's
> Summer of Code with one of the following project ideas.
> 
> Parallel programming benchmarking and benchmark suite
> - http://hackage.haskell.org/trac/summer-of-code/ticket/1544
> 
> Are there open source projects and real world applications that rely
> on GHC's parrallel programming primitives and libraries? I have found

There's many applications on hackage that depend on Control.Concurrent,
forkIO, Channels, MVars and software transactional memory. Relatively
few yet depend on `par` and lightweight parallelism.

> many references to LOLITA, but it seems to be old and not available
> online. The idea page suggests porting existing benchmark suites such
> as PARSEC, but PARSEC is 5G of C code. Most of it seems to come from
> existing applications already written in C. It might also be

Yes, the benefit here would be to build up a set of haskell programs
that do lean on the parallel libraries and primitives. Porting 
algorithms from the benchmark suite would be one useful way to do that.

> interesting to automate the discovery of optimal strategies through
> empirical data, and to modify the thresholds dynamically.
  
See the recent paper by Satnam Singh and Tim Harris,

http://research.microsoft.com/~satnams/fdp.pdf

on feedback-directed implicit parallelism for Haskell.

> Parallel profiling tools for GHC
> - http://hackage.haskell.org/trac/summer-of-code/ticket/1559
> 
> Simon Marlow wrote on the idea page that Gransim was ported to a more
> up-to-date GHC. The documentation available on the web seems to be for
> GHC 0.29 but it describes many options for logging and visualising the
> activity of threads and processors over time. Getting GHC to display
> that information on the frontpanel would make a nice project.
> 
> Do you have any comments or suggestions?
> 
> Thank you,
> 
> Etienne Laurin
> ___
> 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


[Haskell-cafe] [gsoc] mingw64 ghc port

2008-03-28 Thread Bulat Ziganshin
Hello haskell-cafe,

it's probably a bit too late, but i recalled that there is one project
that will be very useful - it's porting ghc to mingw64 platform,
allowing it to generate 64-bit windows platforms. may be someone will
find it interesting

-- 
Best regards,
 Bulat  mailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Sound typeable via type families?

2008-03-28 Thread Ryan Ingram
On 3/27/08, Dan Doel <[EMAIL PROTECTED]> wrote:
>  class Typeable t where
>data TypeRep t :: *
>typeRep :: TypeRep t

This is a really interesting idea.  Sadly, I can't think of a way to
make it work.

The biggest problem is the TEquality class; by putting teq in a
typeclass, the decision of which teq to call (and thus, whether or not
to return Just Refl or Nothing) is made at compile time.  The GADT
solution puts that decision off until run-time; the case statement in
teq allows a decision to be made at that point.

What we'd really like to do is something like the following:

class Typeable t where
data TypeRep t :: *
typeRep :: TypeRep t
typeEq :: forall t2. TypeRep t2 -> Maybe (TEq t t2)

instance Typeable Int where
data TypeRep Int = TInt
typeRep = TInt
typeEq rep = case rep of
TInt -> Just Refl
_ -> Nothing

But you can't case analyze t2 in this way; each TypeRep is an
independent data type and there's no way to determine which one you
have (aside from some sort of typeable/dynamic constraint, and then we
have a circular problem!)

Perhaps there is a solution, but I'm not clever enough to find it.

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


What Does This Message Mean? (Re: [Haskell-cafe] compilation succeeds -- execution fails)

2008-03-28 Thread Jason Dusek
  The message

unknown symbol `___stginit_cedictzm0zi1zi1_DataziCharziCEDICTziMatter_'

  says that it can't find the initializer for`
  Data.Char.CEDICT.Matter` in `cedict-0.1.1` (this is
  'z-encoding', if I remember correctly). So, the odd thing is,
  that is not the part with the C FFI stuff in it -- that's in
  `Data.Char.CEDICT.Lists`. Is there a usual thing that is wrong
  when the initializer can not be found?

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


Re: What Does This Message Mean? (Re: [Haskell-cafe] compilation succeeds -- execution fails)

2008-03-28 Thread Don Stewart
jason.dusek:
>   The message
> 
> unknown symbol `___stginit_cedictzm0zi1zi1_DataziCharziCEDICTziMatter_'
> 
>   says that it can't find the initializer for`
>   Data.Char.CEDICT.Matter` in `cedict-0.1.1` (this is
>   'z-encoding', if I remember correctly). So, the odd thing is,
>   that is not the part with the C FFI stuff in it -- that's in
>   `Data.Char.CEDICT.Lists`. Is there a usual thing that is wrong
>   when the initializer can not be found?
> 

Missing --make 

or possibly missing linking against C libs.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Paul Keir
Could tester2 return "some kind of base type", which the two inherit from? I 
don't know. I'm really only presenting the ugly tester2 function because I'm 
looking for a Parsec-concordant solution to what appears a simple problem.

What I'd like is to parse either the string "parameter", or the string ":". I'm 
using 'reserved' and 'symbol' because they seem to correspond well to the 
concepts in the language I'm parsing. I could try,

tester3 = reserved "parameter" <|> do { symbol ":"; return () }

but that's feels a bit contrived; or I could use 'reserved' twice.

Perhaps I'd express my confusion better if I ask: Why are 'reserved' and 
'symbol' different types?

Paul (Haskell Novice)




-Original Message-
From: Jonathan Cast [mailto:[EMAIL PROTECTED]
Sent: Fri 3/28/2008 2:05 PM
To: Paul Keir
Cc: Luke Palmer; haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Parsec Expected Type
 
On 28 Mar 2008, at 2:02 AM, Paul Keir wrote:

> Thanks, I'd thought it was something to do with incompatible types.  
> I can now create a simpler problem:
>
> tester2 = reserved "parameter" <|> symbol ":"
>
> Certainly I could use reserved ":" instead of symbol, but where is  
> my thinking with symbol here going wrong? Surely the above example  
> isn't so odd?
>
What type do you expect tester2 to return?

jcc


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


Re: [Haskell-cafe] Sound typeable via type families?

2008-03-28 Thread Dan Doel
On Friday 28 March 2008, Ryan Ingram wrote:
> This is a really interesting idea.  Sadly, I can't think of a way to
> make it work.
>
> The biggest problem is the TEquality class; by putting teq in a
> typeclass, the decision of which teq to call (and thus, whether or not
> to return Just Refl or Nothing) is made at compile time.  The GADT
> solution puts that decision off until run-time; the case statement in
> teq allows a decision to be made at that point.
>
> What we'd really like to do is something like the following:
>
> class Typeable t where
> data TypeRep t :: *
> typeRep :: TypeRep t
> typeEq :: forall t2. TypeRep t2 -> Maybe (TEq t t2)
>
> instance Typeable Int where
> data TypeRep Int = TInt
> typeRep = TInt
> typeEq rep = case rep of
> TInt -> Just Refl
> _ -> Nothing
>
> But you can't case analyze t2 in this way; each TypeRep is an
> independent data type and there's no way to determine which one you
> have (aside from some sort of typeable/dynamic constraint, and then we
> have a circular problem!)
>
> Perhaps there is a solution, but I'm not clever enough to find it.

Yes, I thought about it a while longer after sending my mail, and I can't see 
an immediate way of making things work. I imagine one would need some sort of 
open GADTs to do the job. Currently we have two things that look close; GADTs 
which can hold the necessary evidence, but are closed, and type families, 
which are open, but don't allow inspection of values to direct typing.

I suppose I was initially fooled by doing things like:

cast () :: Maybe () ==> Just ()

Which looks just like Data.Typeable. However, when one goes to write more 
generic functions:

foo x = case cast x of
 Just i  -> (show :: Int -> String) i
 Nothing -> "Whatever."

The type of foo ends up as '(TEquality a Int) => a -> String', which makes it 
a bit more clear that we're dealing with compile-time phenomena.

I'll probably think on it some more, but I'm not holding out much hope at this 
point. Thanks for your thoughts, though (and, to Wolfgang, for the pointer to 
the other discussion, although I don't know if that or any of the new type 
families stuff coming in 6.10 will be the solution).

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


Re: [Haskell-cafe] Monad instance for Data.Set, again

2008-03-28 Thread Ganesh Sittampalam

On Fri, 28 Mar 2008, Wolfgang Jeltsch wrote:

But it is possible to give a construction of an Ord dictionary from an 
AssociatedMonad dictionary.  See the attached code.  It works like a 
charm. :-)


This is really cool, and with much wider applicability than restricted 
monads; it gives us a general way to abstract over type class constraints.


The NewMonad class is also very straightforward and I think will cause 
much fewer type-checking headaches and large type signatures than Oleg's 
solution.


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


Re: [Haskell-cafe] Monad instance for Data.Set, again

2008-03-28 Thread Dan Weston

I'm having trouble embedding unconstrained monads into the NewMonad:

> {-# LANGUAGE ...,UndecidableInstances #-}
>
> instance Monad m => Suitable m v where
> data Constraints m v = NoConstraints
> constraints _= NoConstraints
>
> instance Monad m => NewMonad m where
> newReturn   = return
> newBind x k =
>   let   list2Constraints = constraints result
> result = case list2Constraints of
>NoConstraints -> (x >>= k)
>  in result

SetMonad.hs:25:9:
Conflicting family instance declarations:
  data instance Constraints Set val -- Defined at SetMonad.hs:25:9-19
  data instance Constraints m v -- Defined at SetMonad.hs:47:9-19

Since Set is not an instance of Monad, there is no actual overlap 
between (Monad m => m) and Set, but it seems that Haskell has no way of 
knowing that.


Is there some trick (e.g. newtype boxing/unboxing) to get all the 
unconstrained monads automatically instanced? Then the do notation could 
be presumably remapped to the new class structure.


Dan

Wolfgang Jeltsch wrote:

Am Montag, 24. März 2008 20:47 schrieb Henning Thielemann:

[…]



Here is another approach that looks tempting, but unfortunately does not
work, and I wonder whether this can be made working.

module RestrictedMonad where

import Data.Set(Set)
import qualified Data.Set as Set

class AssociatedMonad m a where

class RestrictedMonad m where
return :: AssociatedMonad m a => a -> m a
(>>=)  :: (AssociatedMonad m a, AssociatedMonad m b) => 
m a -> (a -> m b) -> m b


instance (Ord a) => AssociatedMonad Set a where

instance RestrictedMonad Set where
return = Set.singleton
x >>= f = Set.unions (map f (Set.toList x))



[…]


The problem is that while an expression of type

(AssociatedMonad Set a, AssociatedMonad Set b) =>
Set a -> (a -> Set b) -> Set b

has type

(Ord a, Ord b) => Set a -> (a -> Set b) -> Set b,

the opposite doesn’t hold.

Your AssociatedMonad class doesn’t provide you any Ord dictionary which you 
need in order to use the Set functions.  The instance declaration


instance (Ord a) => AssociatedMonad Set a

says how to construct an AssociatedMonad dictionary from an Ord dictionary but 
not the other way round.


But it is possible to give a construction of an Ord dictionary from an 
AssociatedMonad dictionary.  See the attached code.  It works like a 
charm. :-) 


Best wishes,
Wolfgang




___
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] Glome raytracer bug: bad output with -O2 -fasm

2008-03-28 Thread Jim Snow

Luke Palmer wrote:

On Fri, Mar 28, 2008 at 6:28 AM, Jim Snow <[EMAIL PROTECTED]> wrote:
  

I was trying to get Blinn highlights working with my raytracer, and kept
 getting ugly artifacts.  After trying a bunch of things, I finally
 compiled without -O2, and the artifacts went away.

 Here's what I mean:
 http://syn.cs.pdx.edu/~jsnow/glome/Glome.hs-noartifact.png
 http://syn.cs.pdx.edu/~jsnow/glome/Glome.hs-artifact.png

 Here's the offending code, run "./make" and "./run" and you should see
 the artifacts if your setup is the same as mine. (Requires OpenGL.)
 http://syn.cs.pdx.edu/~jsnow/glome/glome.hs-0.2-bug.tar.gz

 The artifacts also go away if I use -fvia-C.  It doesn't seem to matter
 whether I use Floats or Doubles in the rendering code.  The artifacts
 also show up with -O1.  Have I stumbled across a known compiler bug?  Or
 perhaps an OpenGL bug?  (The bug could, of course, be in my code, but
 then one might expect to get the same erroneous output every time
 regardless of compiler flags.)

 To reiterate, I'm using ghc 8.6.2.



You probably mean 6.8.2.

  

Yes, my mistake.  6.8.2.

Works for me in all cases.

% uname -a
Linux madhatter 2.6.22-gentoo-r8 #6 PREEMPT Sat Oct 20 04:19:22 GMT
2007 i686 AMD Turion(tm) 64 Mobile Technology ML-40 AuthenticAMD
GNU/Linux
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.2

Looks to me like Glome is depending on some very fine details of
floating point arithmetic.

Luke
  
After looking into this for awhile, I found that the problem was that in 
computing my Blinn factor:

blinn = fmax 0 $ (vdot halfangle n) ** shine

the (vdot halfangle n) was sometimes negative, resulting in blinn being 
"NaN".  OpenGL apparently interprets "NaN" as "1.0" for the purposes of 
color*, so those patches were rendered bright white.  It's still a bit 
mysterious why the case where (vdot halfangle n) is negative only occurs 
if I compile with "-fasm", but I can work around it for now.


-jim


* I'm using the binary-only nvidia drivers; different OpenGL 
implementations may behave differently.

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


Re: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Ryan Ingram
On 3/28/08, Paul Keir <[EMAIL PROTECTED]> wrote:
> What I'd like is to parse either the string "parameter", or the string ":".
> I'm using 'reserved' and 'symbol' because they seem to correspond well to
> the concepts in the language I'm parsing. I could try,
>
> tester3 = reserved "parameter" <|> do { symbol ":"; return () }

Actually this is exactly on the right track.  But I agree, it looks a
bit contrived.  Maybe this looks better to you?

> tester3 = reserved "parameter" <|> (symbol ":" >> return ())

Or you could factor this behavior out into a new combinator:

> or_ :: Parser a -> Parser b -> Parser ()
> or_ x y = (x >> return ()) <|> (y >> return ())

> tester3 = reserved "parameter" `or_` symbol ":"

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


Re: [Haskell-cafe] Monad instance for Data.Set, again

2008-03-28 Thread Ryan Ingram
On 3/28/08, Dan Weston <[EMAIL PROTECTED]> wrote:
> I'm having trouble embedding unconstrained monads into the NewMonad:

> Is there some trick (e.g. newtype boxing/unboxing) to get all the
> unconstrained monads automatically instanced? Then the do notation could
> be presumably remapped to the new class structure.

The usual trick here is to use newtypes.  (Yes, it sucks)

> newtype OldMonad m = OldMonad m
> unwrapMonad :: OldMonad m -> m
> unwrapMonad (OldMonad m) = m

> instance Monad m => Suitable (OldMonad m) v where
> data Constraints (OldMonad m) v = NoConstraints
> constraints _= NoConstraints
> instance Monad m => NewMonad (OldMonad m) where
> newReturn   = OldMonad . return
> newBind x k = OldMonad $ unwrapMonad x >>= unwrapMonad . k
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Brandon S. Allbery KF8NH


On Mar 28, 2008, at 21:12 , Ryan Ingram wrote:

On 3/28/08, Paul Keir <[EMAIL PROTECTED]> wrote:
What I'd like is to parse either the string "parameter", or the  
string ":".
I'm using 'reserved' and 'symbol' because they seem to correspond  
well to

the concepts in the language I'm parsing. I could try,

tester3 = reserved "parameter" <|> do { symbol ":"; return () }


Or you could factor this behavior out into a new combinator:


or_ :: Parser a -> Parser b -> Parser ()
or_ x y = (x >> return ()) <|> (y >> return ())



tester3 = reserved "parameter" `or_` symbol ":"


Or if you'd like to be inscrutable:

import Data.Function

or_ = (>> return ()) `on` (<|>)

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


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