Re: [Haskell-cafe] Newbie: Applying Unknown Number Arguments to A Partial Function

2006-05-19 Thread Arthur Baars
Chris, the subject states clearly that Aditya is a Newbie, and is most 
likely just trying to define the function map. So I think pointing to 
a bunch of advanced type magic tricks is not really helpful.


Aditya, you say you want the function applyArgument to take a function 
and a list and apply the function to all elements of that list. The 
result of applyArgument is a list, with the results of applying the 
function to each element.


So you want the type of applyArgument to be:
applyArgument :: (a-b) - [a] - [b]


There are a numbers of errors in your code.
applyArgument f (arg) = f arg
The variable f is the first parameter of applyArgument, and has 
type (a - b)
The variable arg is the second parameter of applyArgument, and has 
type [a] .

You try to apply f to a list which is not ok.
Most likely you meant [arg], which is a singleton list, instead of 
(arg), which is the same as just arg
Furthermore applyArgument returns a list of result. The function f 
only yields a b, instead of a list [b]


The following does work:
applyArgument f [arg] = [f arg]

In your second line:
applyArgument f (arg:args) = applyArgument (f arg) args
you use a list pattern (arg:args), which is good. The variable arg 
is the head of the list, and the variable args is the tail of the 
list. So arg has type a, and args has type [a] . The 
application  (f arg) has type b. Because the function 
applyArgument expects a function as first argument and not a b, so 
this is wrong. I guess you can find out by your self how to fix this. 
There are a number of very good tutorials for beginners on 
http://haskell.org .


Finally your function won't work for empty lists, it is only defined 
for singleton lists and longer lists. You can fix this by replacing the 
definition for singleton lists with a definition for the empty list. 
The pattern for empty list is simply [].


Good luck,

Arthur


On 19-mei-06, at 10:10, Chris Kuklewicz wrote:


Aditya Siram wrote:
I am trying to write a function 'applyArguments' which takes a 
function
and a list and recursively uses element each in the list as an 
argument
to the function. I want to do this for any function taking any number 
of

arguments.

applyArgument f (arg) = f arg
applyArgument f (arg:args) = applyArgument (f arg) args

This has failed in Hugs, so my question is: Can I conceptually do 
this?

If so, what is the type signature of this function?

Deech




You can't do that, but there are other tricks that do work:

http://okmij.org/ftp/Haskell/types.html

which describes Functions with the variable number of (variously 
typed)

arguments and Genuine keyword arguments

--
Chris
___
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] Newbie: Applying Unknown Number Arguments to A Partial Function

2006-05-19 Thread Arthur Baars
My apologies to Chris, I think I misinterpreted Aditya's description. 
Thanks to David House for telling me. I thought he was describing a 
function such as map instead of polyvaric functions, which would have 
been more likely for a newbie :-)


So to answer Aditya's question, whether you can do this in Haskell. The 
short answer is no. You cannot do this in plain Haskell. However 
using various extensions to Haskell, you can indeed use the smart 
tricks as Chris pointed out:

http://okmij.org/ftp/Haskell/types.html

Cheers,

Arthur

On 19-mei-06, at 11:24, Arthur Baars wrote:

Chris, the subject states clearly that Aditya is a Newbie, and is most 
likely just trying to define the function map. So I think pointing 
to a bunch of advanced type magic tricks is not really helpful.


Aditya, you say you want the function applyArgument to take a function 
and a list and apply the function to all elements of that list. The 
result of applyArgument is a list, with the results of applying the 
function to each element.


So you want the type of applyArgument to be:
applyArgument :: (a-b) - [a] - [b]


There are a numbers of errors in your code.
applyArgument f (arg) = f arg
The variable f is the first parameter of applyArgument, and has 
type (a - b)
The variable arg is the second parameter of applyArgument, and has 
type [a] .

You try to apply f to a list which is not ok.
Most likely you meant [arg], which is a singleton list, instead of 
(arg), which is the same as just arg
Furthermore applyArgument returns a list of result. The function f 
only yields a b, instead of a list [b]


The following does work:
applyArgument f [arg] = [f arg]

In your second line:
applyArgument f (arg:args) = applyArgument (f arg) args
you use a list pattern (arg:args), which is good. The variable arg 
is the head of the list, and the variable args is the tail of the 
list. So arg has type a, and args has type [a] . The 
application  (f arg) has type b. Because the function 
applyArgument expects a function as first argument and not a b, so 
this is wrong. I guess you can find out by your self how to fix this. 
There are a number of very good tutorials for beginners on 
http://haskell.org .


Finally your function won't work for empty lists, it is only defined 
for singleton lists and longer lists. You can fix this by replacing 
the definition for singleton lists with a definition for the empty 
list. The pattern for empty list is simply [].


Good luck,

Arthur


On 19-mei-06, at 10:10, Chris Kuklewicz wrote:


Aditya Siram wrote:
I am trying to write a function 'applyArguments' which takes a 
function
and a list and recursively uses element each in the list as an 
argument
to the function. I want to do this for any function taking any 
number of

arguments.

applyArgument f (arg) = f arg
applyArgument f (arg:args) = applyArgument (f arg) args

This has failed in Hugs, so my question is: Can I conceptually do 
this?

If so, what is the type signature of this function?

Deech




You can't do that, but there are other tricks that do work:

http://okmij.org/ftp/Haskell/types.html

which describes Functions with the variable number of (variously 
typed)

arguments and Genuine keyword arguments

--
Chris
___
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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Small syntax question

2006-02-13 Thread Arthur Baars
The problem is that the semicolon after let a = 3 is consumed as part 
of the let-declaration.
To make sure that the semicolon is not parsed as part of the let, you 
need to indent it less than the variable a.

For example:

module Main where
main = do {
let a = 3
; return ();
};

Arthur


  Why isn't this one [valid]?

module Main where
main = do {
let a = 3;
return ();
};



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


Re: [Haskell] Compiling wxHaskell from source?

2005-11-17 Thread Arthur Baars
Wouter Swierstra succeeded compiling wxhaskell for Mac OSX Tiger. See 
his messages on the wxhaskell-mailinglist:

http://sourceforge.net/mailarchive/forum.php?forum_id=34197


From: Wouter Swierstra [EMAIL PROTECTED].Nott.AC.UK
Re: Installation on Mac OS X  
2005-11-09 04:42
Yep, that fixes it.

Thanks again for everyone's help.

--Wouter

For the record, here's what I had to do

Download wxMac2.6.2

  cd wxMac-2.6.2/
  mkdir mybuild
  cd mybuild
  ./configure --disable-shared --disable-unicode
  make
  sudo make install

Download and unpack wxHaskell 0.9.4

comment out the function wxColour_GetPixel in wxhaskell-0.9.4/wxc/src/
ewxw/eljcolour.cpp

 ./configure --wx-config=/usr/local/bin/wx-config
 make
 make install


Cheers,

Arthur
On 17-nov-05, at 22:29, Joel Reymont wrote:


I cannot build it on Mac OSX either. I think it has to do with GCC 4.x.

On Nov 17, 2005, at 9:09 PM, Deling Ren wrote:

Hi there, is there anyone out there having luck with compiling 
wxHaskell from source on Debian? My Debian version is 3.1, ghc 6.4.1 
from sid. wxWidgets 2.6.3. wxHaskell version is 0.9.4. gcc version is 
4.0.3. I got the following error messages when trying to run make.


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


Re: type annotations for GADTs

2005-09-29 Thread Arthur Baars

I think it is a bug.

It also works with silly type annotations:
doy :: Y X a b - Y X a b
doy (Y (X :: foo)(X :: bar)) = Y X X

Looks like something smart is happening in the Pattern Annotation rule.

Arthur

On 29-sep-05, at 12:40, Ganesh Sittampalam wrote:


Hi,

I found it slightly surprising that the program below (also attached 
as a file) needs the nested type annotations in the place commented. 
It's not really clear whether it's a bug or just a natural consequence 
of GADT type-checking, but since Simon Marlow also found it surprising 
it at first glance, I thought I'd send it in for comment.


The intuitive argument I came up with for why it might be necessary is 
that each GADT requires some kind of type signature in argument 
position to generalise its type correctly, and the overall signature 
for doy isn't enough to generalise the type of the X arguments.


Cheers,

Ganesh

data X a b where
   X :: X a a

data Y x a b where
   Y :: x a b - x b c - Y x a c

{- This needs the nested type annotations -}
doy :: Y X a b - Y X a b
doy (Y (X :: X a c) (X :: X c b)) = Y X X

data YX a b where
   YX :: X a b - X b c - YX a c

{- This version doesn't need them -}
doyx :: YX a b - YX a b
doyx (YX X X) = YX X 
XGADT.hs___

Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [Haskell-cafe] mistake in Gentle Introduction

2005-09-22 Thread Arthur Baars


On 22-sep-05, at 11:20, Tomasz Zielonka wrote:


On 9/22/05, Simon Marlow [EMAIL PROTECTED] wrote:


 The error message on this is really poor: parse error on input
 `length'

 An addition like expecting '(' might be more helpful.

Not easy to do - some significant work on Happy would be required (or
rewriting GHC's parser, which is even more unlikely).

However we *would* like to do some simple error recovery in the parser
at some point.  The main reason for doing this is to get better 
results

from checking partially complete modules in Visual Haskell or hIDE.
 How about using the parser made by Arthur Baars, trading speed for 
better error messages?

 Maybe even the speed issue could be solved.


Speed, error messages and recovery were not my main concern when 
writing the parser. I think a lot can be gained by optimizing the 
combinator-based parsers. However this is no fun. I had to do some 
left-factorization to gain reasonable efficiency(at first the speed was 
sometimes worse than 1 token per minute :-)). For a complex language 
such as Haskell, the code resulting from factorization is really messy 
and the notational elegance of the combinators is lost. Maybe someone 
can write a parser-generator that uses Doaitses parsing-engine as a 
back-end :-)


A main feature of Doaitses parsing-combinators is that they can recover 
from an error in the input. This is done by considering a number of 
alternatives to repair the input, and taking the best one to 
continue parsing. This proces can be improved by tweaking the insert 
and delete costs of certain symbols. Furthermore the error messages can 
be customized as with Parsec.


___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [Haskell-cafe] wxHaskell: getting a checkbox state

2005-09-14 Thread Arthur Baars

Hi,

A Checkbox is instance of the class Checkable:
http://wxhaskell.sourceforge.net/doc/ 
Graphics.UI.WX.Classes.html#t%3ACheckable


This means you can get and set the checked property for  
checkboxes.

for example:
 c - get cbEdit checked
 set cbEdit [checked := not c ]

The following code makes the checkbox print its state every time it is  
checked or unchecked:

   cbEdit - checkBox f [text := Edit Mode ]
   set cbEdit [ on command :=  do v - get cbEdit checked
  print v
  ]
Arthur

PS: there is a mailinglist for wxhaskell-related questions:
http://lists.sourceforge.net/lists/listinfo/wxhaskell-users

On 14-sep-05, at 17:15, Mark Carter wrote:

I'm a complete n00b to Haskell, and I am trying to write an  
experimental app using wxHaskell. I'm getting on suprisingly well,  
given that I have practially no idea what I'm doing.


In my main loop I have
   cbEdit - checkBox p1 [text := Edit Mode, on command :=  onCbEdit  
textlog   ]
where p1 is a panel, and textlog is a textCtrl that I want to write  
output to. In my where clause I have defined:


  onCbEdit textlog  = do
   appendText textlog onCbEdit\n

So far, this works. The thing that's got me totally stumped is this:  
suppose I want onCbEdit to do something dependent on the state of the  
checkbox (i.e. whether it is checked or unchecked). I've tried a  
variety of things, but I can't get anything to work.


To put things into a wider context, here's the message I posted to  
fa.haskell yesterday:


I'm the rawest of n00bs to Haskell. I was interested in evaluating it,
and I've seen some GUI stuff that looked pretty impressive.

I wanted to write a protoype for a commercial application to do
hydrocarbon accounting. Which is to say, you've a number of so-called
streams - think of them as graph nodes - feeding into each other in a
directed fashion (assume the graph is acyclic). Then there's a bunch of
business logic which determines how the values of one stream are
affected by the values in another. An example of a stream might be a
platform. Another one might be a well. Each stream would display on the
window as some funky symbol, with its name underneath.

It would be nice if the application had an edit mode, where you could
add, move, delete, and join streams in a window; and a data mode, where
you could click on the stream you were interested in  and examine its
properties.

Is there a Haskell GUI toolkit which is particularly suitable for this?

Other requirements of the toolkit would be:
* Works on Windows (XP)
* commercial-friendly licence: GPL is out, and even LGPL is a bit
fiddly
* free
* bonus points for being easy to use, and well-documented


___ To help  
you stay safe and secure online, we've developed the all new Yahoo!  
Security Centre. http://uk.security.yahoo.com

___
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


GADT: weird error message

2005-09-12 Thread Arthur Baars
In the code below the function trans is accepted by GHC 6.4, but 
trans1 is not. I would expect that (x,y) is just syntactic sugar 
for (,) x y, but apparently it isn't. I guess this is a bug; can 
anyone explain what is going on?


Cheers,

Arthur

The Code:
data Equal a b where
 Eq :: Equal a a

trans :: forall a b c. Equal a b - Equal b c - Equal a c
trans = \x - \y - case (,) x  y  of
(Eq,Eq ) - Eq

trans1 :: forall a b c. Equal a b - Equal b c - Equal a c
trans1 = \x - \y - case (x, y)  of
(Eq,Eq ) - Eq

The error message:
Test2.hs:9:0:
Quantified type variable `c' is unified with another quantified 
type variable a

When trying to generalise the type inferred for `trans1'
  Signature type: forall a b c. Equal a b - Equal b c - Equal 
a c

  Type to generalise: Equal a b - Equal b a - Equal a a
In the type signature for `trans1'
When generalising the type(s) for `trans1'

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


GADT: weird error message

2005-09-06 Thread Arthur Baars
In the code below the function trans is accepted by GHC 6.4, but 
trans1 is not. I would expect that (x,y) is just syntactic sugar 
for (,) x y, but apparently it isn't. I guess this is a bug; can 
anyone explain what is going on?


Cheers,

Arthur

The Code:
data Equal a b where
 Eq :: Equal a a

trans :: forall a b c. Equal a b - Equal b c - Equal a c
trans = \x - \y - case (,) x  y  of
(Eq,Eq ) - Eq

trans1 :: forall a b c. Equal a b - Equal b c - Equal a c
trans1 = \x - \y - case (x, y)  of
(Eq,Eq ) - Eq

The error message:
Test2.hs:9:0:
Quantified type variable `c' is unified with another quantified 
type variable a

When trying to generalise the type inferred for `trans1'
  Signature type: forall a b c. Equal a b - Equal b c - Equal 
a c

  Type to generalise: Equal a b - Equal b a - Equal a a
In the type signature for `trans1'
When generalising the type(s) for `trans1'

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [Haskell] ANNOUNCE: ghc-src version 0.2.0

2005-08-30 Thread Arthur Baars

You can check them out using CVS as follows:

cvs -d:pserver:[EMAIL PROTECTED]:/data/cvs-rep login
cvs -d:pserver:[EMAIL PROTECTED]:/data/cvs-rep checkout uust

I'll ask Doaitse to add this information to the web page.

Arthur

On 30-aug-05, at 13:53, Benjamin Franksen wrote:


On Tuesday 30 August 2005 13:04, Arthur Baars wrote:

Daan is right, I wrote a parser for GHC using Doaitse Swierstra's
parsing combinator library
(http://www.cs.uu.nl/groups/ST/Software/UU_Parsing/index.html).


Very interesting. I tried to download it but I had no success. How
exactly do I checkout the whole uust tree?

Ben
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell



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


Re: [Haskell-cafe] Parse error

2005-03-17 Thread Arthur Baars
You need { } around the declaration of matrix1. Otherwise the semicolon  
at the end of its definition is considered to be part of the 'let':

let { matrix1 = (array ((1,1),(3,3)) [((1,1), 0.0), ((1,2), 0.0),  
((1,3),-2.0), ((2,1), 0.0), ((2,2), 7.0),  ((2,3), 0.0), ((3,1), 0),  
((3,2), 0), ((3,3), -3)])} ;

The layout rule will otherwise add { } as follows:
do { let x = 10 ;
 putStr hello ;
   }
--
do { let { x = 10 ; empty decl }
 putStr hello ;
   }
which is wrong, because there is no semicolon separating the  
'let'-declaration from the 'putStr' expression.

A solution is to use layout instead of { ; } or write semicolons in  
front of declarations:

do { let x = 10
   ; putStr hello
   }
This translates into:
do { let { x = 10 }
   ; putStr hello
   }
The semicolon is not part of the 'let' declaration, because it is  
indented less than 'x' .

For more information, see:
http://haskell.org/onlinereport/syntax-iso.html#layout
Hope this helps,
Arthur

On 17-mrt-05, at 20:42, Dmitri Pissarenko wrote:
Hello!
In the attachment you will find a file, in which I try to access Java  
from
Haskell using the Java bridge for functional languages.

For details see
http://sourceforge.net/projects/jvm-bridge/
and
http://dapissarenko.com/resources/2005_02_17_eigenvaluesJava/ 
2005_02_17_eigenva
luesJava.pdf

When I try to compile the attached file using
ghc +RTS -c -RTS -package javavm  -c EigenvalueCalculatorHaskell.hs -o
EigenvalueCalculatorHaskell.o
I get the error
EigenvalueCalculatorHaskell.hs:28: parse error on input `putStrLn'
Unfortunately, I have not the slightest idea about how to fix/isolate  
it (I
already commented out almost the whole code).

Please tell me what I could try to correct the error. I appreciate ANY  
hint.

Many thanks in advance
Dmitri Pissarenko
PS: The source code of the files related to  
EigenvalueCalculatorHaskell.hs is
located at

http://dapissarenko.com/resources/2005_02_17_eigenvaluesJava/ 
2005_02_17_lik.zip

--
Dmitri Pissarenko
Software Engineer
http://dapissarenko.com
EigenvalueCalculatorHaskell.hs___ 

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] Parser problem continued

2005-03-15 Thread Arthur Baars
The layout of your code is very important when writing haskell code:
Your code :
expr = do t - term
  do symbol +
 e - expr
 return e
  return (t + e)
   +++ return t
is equivalent to:
expr = do { t - term
  ; do { symbol +
   ; e - expr
   ; return e
   }
  ; return (t + e) -- e is not in scope
  }
   +++ return t -- t is not in scope
Both t and e are not in scope:
* e is in a nested do-block
* the expression 'return t' is outside the do-block
What you probably mean is:
expr = do t - term
  do symbol +
 e - expr
 return (t + e)
 +++ return t
which is equivalent to:
expr = do { t - term
  ; do { symbol +
   ; e - expr -- (dropped the return e line)
   ; return (t + e)
   }
   +++ return t
  }
Now t and e are in scope. The parser 'expr' will first recognize a 
'term' and then try to recognize a '+' symbol followed by an 
expression. If that fails it returns 't'.

Cheers,
Arthur
On 15-mrt-05, at 16:28, Nicola Whitehead wrote:
Curiouser and curiouser...
 
expr :: Parser Int
expr = do t - term
  do symbol +
 e - expr
  return (t + e)
   +++ return t
solves the undefined variable problem but introduces a new 'Last 
operator in do {...} must be an expression' error, which then 
disappears if I explicitly return e
 
expr :: Parser Int
expr = do t - term
  do symbol +
 e - expr
     return e
  return (t + e)
   +++ return t

to give me the original undefined variable t error at the line expr = 
do t - term . It looks in scope to me... :(
 
Thanks,
 
Nik
 
Dr Nik Freydís Whitehead
University of Akureyri, Iceland
*
Having the moral high ground is good.
Having the moral high ground and an FGMP-15 is better.
*
 
___
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] Must be a FAQ - Can't make install Hugs98-Nov2003 on MacOSX 10.3.8

2005-02-25 Thread Arthur Baars
See the hugs-bugs archive:
http://www.mail-archive.com/hugs-bugs@haskell.org/msg02815.html
Malcolm Wallace wrote:
The configure script is (wrongly) determining that the MacOS X C
compiler does not support Floats/Doubles.  Ideally, the autoconf magic
which determined this setting should be fixed, but in the meantime,
you can work around it by:
  (1) Edit src/config.h, replacing the line
  /* #undef HAVE_LIBM */
  with
  #define HAVE_LIBM 1
  (2) rm src/*.o
  (3) cd src; make
Regards,
Malcolm
Hope this answers your question.
Arthur
On 25-feb-05, at 16:09, Kaoru Hosokawa wrote:
I'm sure this must be a FAQ, but I can't make install hugs98-Nov2003 
on MacOS 10.3.8. The error message I get is:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem with type signature in local function

2004-12-24 Thread Arthur Baars
You could also do it with the current implementation of scoped type 
variables. So you don't need to compile the CVS HEAD version. Note that 
you need the pattern (n1::a) and/or (n2::a) to introduce the scoped 
type variable, which was not necessary in Ralf's solution.

{-# OPTIONS -fglasgow-exts #-}
add :: Num a = a - a - a
add (n1::a) n2 = addToN1 n2
   where addToN1 :: a - a
 addToN1 number = n1 + number
Cheers,
Arthur
On 24-dec-04, at 13:04, Ralf Laemmel wrote:
Timely question. :-)
GHC supports lexically scoped type variables.
And this support has just been _extended_ to be readily useful for you
(see discussion on the ghc list just a few days back).
With GHC CVS HEAD the following program works fine.
(Note that I removed the inner Num constraint.)
{-# OPTIONS -fglasgow-exts #-}
add :: Num a = a - a - a
add n1 n2 = addToN1 n2
  where addToN1 :: a - a
addToN1 number = n1 + number
... even though I would not claim that this is a really strong example
of lexically scoped variables, but you probably just simplied a real 
code example.
And most of my recent code I use lexically scoped type variables
extensively. They are great.

(In principle, one does not need them at the cost of encoding. Using 
asTypeOf and friends ...)

Merry Xmas,
Ralf
Christian Hofer wrote:
Hi,
in order to understand the reason for strange compiler error 
messages, I often find it convenient to add type signatures to every 
function. But sometimes this seems to be impossible when using type 
variables.

I try to give a very easy example:
add :: Num a = a - a - a
add n1 n2 = addToN1 n2
   where addToN1 :: Num a = a - a
 addToN1 number = n1 + number
ghc says Inferred type is less polymorphic than expected, and 
justly so, because the type variable a in addToN1 must of course be 
the same as in add. Is there a way to specify this?

Regards,
Chris
___
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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: generalised algebraic data types, existential types, and phantom types

2004-07-23 Thread Arthur Baars
You could make use of the equality data type[1,2]:
newtype Equal a b = Eq (forall f . f a - f b)
cast :: Equal a b - (a - b)
cast (Equal f) = f id
Your data type would be:
data Term a = Lit Int (Equal Int a)
| Inc (Term Int) (Equal Int a)
| ...
| forall b c . Pair (Term b) (Term c)  (Equal (b,c) a)
eval :: Term a - a
eval (Lit x eq) = cast x eq
eval ... = ...
A value of type 'Equal a b' serves as a proof that 'a' and 'b' are 
equal. Its use is described in [1] and [2]. Pasalic [3] makes use of 
this type to implement typed abstract syntax. This paper describes what 
you are trying to achieve with your 'Term' data type.

Arthur
[1]Typing Dynamic Typing, Arthur Baars and Doaitse Swierstra. ICFP 2002.
http://www.cs.uu.nl/~arthurb/dynamic.html
[2]A lightweight implementation of generics and dynamics, James Cheney 
and Ralf Hinze. Haskell Workshop 2002, Pittsburgh, PA, 2002.
http://www.cs.cornell.edu/people/jcheney/papers/Dynamic-final.pdf

[3]Emir Pasalic: Meta-Programming with Typed Object-Language 
Representations.
http://www.cse.ogi.edu/~pasalic/

On 22-jul-04, at 18:06, Jim Apple wrote:
I tried to post this to gmane.comp.lang.haskell.general, but it never 
got there - it may belong here anyway.

Abraham Egnor wrote:
 Is there any closer approximation [of GADTs] possible?
{-# OPTIONS -fglasgow-exts #-}
{-# OPTIONS -fallow-undecidable-instances #-}
data Term a = forall b . (EqType a b, EqType b Int) = Lit Int
| forall b . (EqType a b, EqType b Int) = Inc (Term Int)
| forall b . (EqType a b, EqType b Bool) = IsZ (Term Int)
| If (Term Bool) (Term a) (Term a)
| forall b . Fst (Term (a,b))
| forall b . Snd (Term (b,a))
| forall b c . (EqType a (b,c))= Pair (Term b) (Term c)
class EqType a b | a-b, b-a
instance EqType a a
Unfortunately, I can't seem to write an eval function:
eval (Lit a) = a
gives
Inferred type is less polymorphic than expected
Quantified type variable `b' is unified with `Int'
When checking an existential match that binds
The pattern(s) have type(s): Term Int
The body has type: Int
In the definition of `eval': eval (Lit x) = x
Any ideas?
Jim
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What's wrong with my Haskell code?

2004-04-13 Thread Arthur Baars
It is because you use 'div' instead of '/'.

div :: Integral a = a - a - a

(/) :: Fractional a = a - a - a

Rationals are instance of the class Fractional, but not of Integral
Prelude :i Fractional
class Num a = Fractional a where
  (/) :: a - a - a
  recip :: a - a
  fromRational :: Rational - a
  fromDouble :: Double - a
-- instances:
instance Fractional Float
instance Fractional Double
instance Integral a = Fractional (Ratio a)
Hope this helps,

Arthur

On 13-apr-04, at 20:44, Meihui Fan wrote:

when loading the following code, hugs escaped and reported that

ERROR cal24.hs:10 - Instance of Integral (Ratio Integer) required 
for definition of Main.eval

I don't know why and how to solve it, anyone help me?

data ETree = Add ETree ETree
   | Sub ETree ETree
   | Mul ETree ETree
   | Div ETree ETree
   | Node Integer
   deriving Show
eval :: ETree-Maybe Rational
eval (Node x)= Just (fromInteger x)
eval (Add t1 t2) = do { x-eval t1; y-eval t2;
if x=y then return (x+y) else Nothing }
eval (Sub t1 t2) = do { x-eval t1; y-eval t2; return (x-y) }
eval (Mul t1 t2) = do { x-eval t1; y-eval t2;
if x=y then return (x*y) else Nothing }
eval (Div t1 t2) = do { x-eval t1; y-eval t2;
if y/=0 then return (x `div` y) else Nothing }
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: lexer puzzle

2003-09-15 Thread Arthur Baars
I agree with Marcin,

A... should be split into A.. and .

As I read the (on-line) report the maximal munch rule says that you 
should read the longest lexeme. It does not say that two operators have 
to be separated by whitespace.

Because A... is not a lexeme, the longest lexeme you can read from 
A... is A.. (qualified dot-operator).

Arthur

On maandag, sep 15, 2003, at 12:11 Europe/Amsterdam, Malcolm Wallace 
wrote:

Marcin 'Qrczak' Kowalczyk [EMAIL PROTECTED] writes:

Argh, I was wrong. It's A.. (qualified operator), then . (operator).
You are forgetting about the maximal munch rule.  An operator cannot 
appear
directly next to another operator without some whitespace to separate 
them.
For instance A.+. is an operator called (+.) from module A, not an
operator called + followed by compose.

But, although A could be the three-dot operator ... from the
module A, it is not possible to have A... interpreted as a two-dot
operator, because .. is reserved as sugar for enumeration sequences,
and so is explicitly excluded from the varsym production.
Thus, the only possible lexical interpretation is the one you first
suggested, namely a constructor A followed by a three-dot operator

Regards,
Malcolm
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Announce: wxhaskell: MacOSX installer

2003-07-24 Thread Arthur Baars
I have created an out-of-the-box MacOS X installer for wxHaskell. Simply 
double-click on the package. The installer can be downloaded from:
http://home.deds.nl/~dediav/WxHaskell.dmg
This link is only valid for a couple of weeks. After Daan returns from 
holidays he'll probably put it on the wxHaskell pages.

Note the package only works with ghc 6.0 or higher!

The installer does the following:
1) copy wxWindows and wxHaskell libraries to /usr/local/wxhaskell
2) register the wx and wxh packages with ghc-pkg
To uninstall, type in a Terminal:
1) rm /usr/local/wxhaskell
2) ghc-pkg -r wxh
3) ghc-pkg -r wx
The package also contains the wxHaskell documentation and samples. Copy them 
to your disk.
To test the installation:
Open a terminal in the samples/wx directory, and write:
1) ghc --make -package wx Camels.hs -o camels
2) /usr/local/wxhaskell/bin/macosx-app --program=camels
3) ./camels

The macosx-app script is located at /usr/local/wxhaskell/bin; you may want 
to add this directory to your PATH.

Have fun :-))

Arthur

From: Daan Leijen [EMAIL PROTECTED]
Date: din jul 22, 2003  19:47:27 Europe/Amsterdam
To: [EMAIL PROTECTED], [EMAIL PROTECTED], 
[EMAIL PROTECTED]
Subject: [wxhaskell-users] Announce: wxhaskell: macOSX binaries and bugfix.
Reply-To: [EMAIL PROTECTED]

Two announcements regarding wxHaskell:
http://wxhaskell.sourceforge.net
1) I have created a binary release for MacOS X. Installation details can
 be found on the download page.
2) I have fixed a small bug in the configuration script for Linux. The
 source release has been updated. (and I promise I won't do that again
  as I go tomorrow on a holiday for two weeks :-)
All the best,
 Daan.
_
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


GHC 6 for Mac OS X: fix for package util/readline

2003-07-21 Thread Arthur Baars
On Mac OS X GHCi 6.0 complains about a missing symbol when trying to 
load package util. Wolgang Thaller told me the cause of this bug:

The problem was that there was a file called HsReadline.c. The 
corresponding
object file, HsReadline.o, replaced HSreadline.o on the Mac's
case-insensitive file system.

So the actual problem is a broken readline package, which is used by 
util.
The bug is fixed in the next release (6.0.1) and in CVS. For those who 
don't feel like compiling CVS-sources, or waiting for the next release; 
below is a quick fix. A working HSreadline.o is created from the 
libHSreadline.a file using the -g option of ghc-pkg.

1) set environment variable libdir to ghc-6's directory:
setenv libdir /usr/local/lib/ghc-6.0/
2) cp $libdir/libHSreadline.a $libdir/libHSreadline_p.a /tmp/
3) create a config file for package readline:
ghc-pkg -s readline  /tmp/readline.conf
4) cd /tmp
5) remove the package readline from ghc:
ghc-pkg -r readline
6) add package again and let ghc-pkg create the ghci library:
ghc-pkg -g -a -i /tmp/readline.conf
For step 5/6 you may need root-access, use su or sudo

Arthur

___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: clueless GHCI user wishes to load QuickCheck

2003-03-11 Thread Arthur Baars
QuickCheck is in de util package. You can load a package with the 
-package flag:

$ ghci -package util
Prelude :browse QuickCheck
class Arbitrary a where {
arbitrary :: Gen a; coarbitrary :: forall b. a - Gen b - Gen b; }
arbitrary :: forall a. (Arbitrary a) = Gen a
...
Prelude:module QuickCheck
Prelude QuickCheck :info trivial
-- trivial is a variable
trivial :: forall a. (Testable a) = Bool - a - Property
Hope this helps.

Cheers,

Arthur

On Tuesday, March 11, 2003, at 07:02 PM, Norman Ramsey wrote:

Can anyone help me figure out how to load QuickCheck into GHCI?
QuickCheck is included in my Debian package, but my attempts
at loading it are bootless:
Prelude :load QuickCheck
can't find module `QuickCheck'
Prelude :load util/QuickCheck
can't find module `util/QuickCheck'
Prelude :info
syntax: `:i thing-you-want-info-about'
Prelude :load util/QuickCheck.hi
can't find module `util/QuickCheck.hi'
Prelude :load /usr/lib/ghc-5.02.2/imports/util/QuickCheck.hi
can't find module `/usr/lib/ghc-5.02.2/imports/util/QuickCheck.hi'
Prelude :load /usr/lib/ghc-5.02.2/imports/util/QuickCheck
can't find module `/usr/lib/ghc-5.02.2/imports/util/QuickCheck'
Prelude
Any advice, anyone?

Norman
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Building snapshot ghc-5.05.20030123 on macOSX

2003-02-12 Thread Arthur Baars
I want to play a bit with Template Haskell, so I downloaded a cvs 
snapshot (ghc-5.05.20030123.tar.gz) and tried to compile
it on my mac (OSX 10.2).  I figured out that I needed a stage2 or 
stage3 compiler to get TH working, so I tried 'make stage3' .
GHC started to compile itself three times. At lot of hours later it 
finished.

Unfortunately, when I tried run the thing on a Prinf example, I got the 
following message.
compiler/stage3- ./ghc-inplace -c Printf.hs -fglasgow-exts -package 
haskell-src
Template Haskell  bracket illegal in a stage-1 compiler
  [| \s - s |]

The thing incompiler/stage3  was just a stage-1 compiler, so ghc had 
achieved nothing useful after re-compiling three times :-(
The problem is that GHCi support is not turned on for MacOSX. I guess 
GHCi is used to do compile-time evaluation of code for TH.

In file mk/config.mk.in it says:

# Include GHCi in the compiler.  Default to NO for the time being.

ifneq $(findstring $(HostOS_CPP), mingw32 cygwin32 linux solaris2 
freebsd netbsd openbsd) 
GhcWithInterpreter=YES
else
GhcWithInterpreter=NO
endif

In the list of supported systems MacOSX is missing. After adding 
darwin to this list, and waiting for hours, I got a working 
TH-compiler.

Can someone add OSX(darwin) to the mk/config.mk.in file? It would 
also be nice to get a warning
if one tries to compile a stage-(N1) compiler without GHCi support.

Cheers,

Arthur

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: question about parsing integers and floats with Parsec

2002-08-16 Thread Arthur Baars

Hi,

Here is a solution that does not use try.


import Parsec
import qualified ParsecToken as P
import ParsecLanguage (emptyDef)

lexer  = P.makeTokenParser emptyDef

-- naturalOrFloat parses a float or an integer without sign
naturalOrFloat = P.naturalOrFloat lexer
   
data Sign  = Positive | Negative

applySign  :: Num a = Sign - a - a
applySign Positive =  id
applySign Negative =  negate
   
sign  :: Parser Sign
sign  =  do { char '-'
; return Negative
}
 | do { char '+'
; return Positive
}
 | return Positive

genericgrab :: Parser (Either Integer Double)
genericgrab =  do { s   - sign
  ; num - naturalOrFloat
  ; return (case num of
  Right x - Right (applySign s x)
  Left  x - Left  (applySign s x)
   )
  }


On 16/8/02 7:08, Harris, Andrew [EMAIL PROTECTED] wrote:

 Hi -
 
 After a bit of monkeying around, it seems the following parser works
 to detect both integers and floats, both positive and negative.  I'm sure
 you wizards have many better ways of doing this.  Anyway here it is for your
 amusement:
 
 import Parsec
 import qualified ParsecToken as P
 import ParsecLanguage (emptyDef)
 
 lexer = P.makeTokenParser emptyDef
 integer = P.integer lexer
 float = P.float lexer
 
 genericgrab :: Parser (Either Integer Double)
 genericgrab = try ( do { n - char '-'
 ; f - float
 ; return (Right (-f))
 }
 )
| try ( do { f - float
 ; return (Right f)
 }
)
| try ( do { f - integer
  ;  return (Left f)
  }
)
 
 -andrew
 
 -Original Message-
 From: Harris, Andrew [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, August 15, 2002 6:55 PM
 To: '[EMAIL PROTECTED]'
 Subject: question about parsing integers and floats with Parsec
 
 
 Hi -
 
 This isn't a pure Haskell question, but I'm trying to use the
 Parsec library to parse out space separated numbers, which
 could be integers
 or floats and either positive or negative.  I was using the
 naturalOrFloat
 lexeme parser from the ParsecToken module, until I realized
 that it doesn't
 seem to handle negative integers.  I've been poking with
 trying to pair the
 integer and float lexeme parsers with try() blocks, but I
 ain't no parsing
 expert and am not making good progress.
 
 Any help/hints would be appreciated!
 
 thanks,
 -andrew
 
 ---
 Andrew Harris[EMAIL PROTECTED]
 ___
 Haskell-Cafe mailing list
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 ___
 Haskell-Cafe mailing list
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 

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



Existentials and newtype

2001-11-22 Thread Arthur Baars

At [EMAIL PROTECTED] I asked the following:

 this works

data Exists f = forall x . E ( f  x)

 this doesn't work

 newtype Exists f = forall x . E ( f  x)

 Hugs accepts both.

 It there a reason why existential quantification does not work with a
 newtype, or is it just
 a parser problem?

This problem is clearly not a bug but a restriction imposed by the designers
of GHC,
as Keith Wansbrough pointed out to me:

 From the manual, section 7.12.3 Restrictions:

 --8--
 You can't use existential quantification for newtype declarations. So this
is illegal:
   newtype T = forall a. Ord a = MkT a

 Reason: a value of type T must be represented as a pair of a
 dictionary for Ord t and a value of type t. That contradicts the idea
 that newtype should have no concrete representation. You can get just
 the same efficiency and effect by using data instead of newtype. If
 there is no overloading involved, then there is more of a case for
 allowing an existentially-quantified newtype, because the data because
 the data version does carry an implementation cost, but single-field
 existentially quantified constructors aren't much use. So the simple
 restriction (no existential stuff on newtype) stands, unless there are
 convincing reasons to change it.
 --8--

I perfectly understand why the use of class constraints in combination with
newtype and existential quantification is
illegal. In my opinion the restriction should only forbit this particular
combination, instead of all uses of newtype with existentials.

For me single-field existentially quantified constructors are quite useful:

For example

newtype Exists f = forall x . E (f x)

data Object a = Object {value :: a , toString:: a - String }

data Thing a = Thing {val :: a , next :: a - a,  run :: a - IO ()}

-- Here I hide the type variables of Object and Thing using the type Exists:

type EObject  = Exists Object
type EThing= Exists Thing

without single-field existentially quantified constructors I would have to
write:

data EObject =  forall  a . EObject a (a - String)
data EThing   =  forall a . EThing  a  (a - a)  (a- IO ())

or write the Exists type using data

When using data I have to pay a (however small) run-time cost, that I would
not have to pay
when using a newtype.

The other solution does not have this run-time cost, but it makes my code
less readable:
I have to invent new types and constructor names.
I cannot use named fields.
I cannot reuse polymorphic functions that work on Object on EObjects.

Summarizing: without single-field existentially quantified constructors in
newtypes
either my code gets less readable or I have to pay a run-time price.
 Is it possible to relax the restriction on newtypes in combination with
existentials?

Cheers, Arthur











___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Exists for all places

2001-11-20 Thread Arthur Baars

I see the difference in behaviour of the parser for newtype and data
definitions in combination with universal quantifications,
as reported by Ralf Hinze (forall for all places, October 2001), has been
fixed in GHC version 5.02.1.

I encountered a similar problem with existential quantification:

this works

 data Exists f = forall x . E ( f  x)

this doesn't work

 newtype Exists f = forall x . E ( f  x)

Hugs accepts both.

It there a reason why existential quantification does not work with a
newtype, or is it just
a parser problem?

Cheers, Arthur


___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs