[Haskell-cafe] Re: Some random newbie questions

2005-01-10 Thread John Hughes
I seriously considered switching frlom Hugs to GHC for my introductory 
programming class this year, but in the end stayed with Hugs because of 
a single feature.

I'm teaching beginning programmers, and for them at least, there is an 
overwhelming volume of names to learn -- what's that function? is a 
question they ask themselves often, as is what's that type?. I teach 
them that, whenever they see a name they don't recognise, they can find 
out more about it using the :i command. This is a simple trick to learn, 
that helps them understand points they've missed and catches 
misapprehensions.

My students also see type classes very early. I'll bet yours will too. 
Even if one is very careful to restrict the examples in lectures so as 
to avoid them (which is a bind), as soon as students try out Hugs for 
themselves, they will make mistakes that generate error messages 
referring to type classes. No problem: the question what's that class? 
can ALSO be answered by :i.

Now, at the beginning students have only a very rudimentary 
understanding of classes. A class is a collection of types to them, 
nothing more. In particular, the class definition itself is of little 
use to them, since it often contains a very subtly chosen collection of 
methods (just type :i Show, for example, which students do very early). 
What IS useful, right from the beginning, is the list of instances. What 
are Num types? Oh, integers and reals.  What are Show types? Oh, pretty 
much everything. Particularly when debugging missing instance errors, 
this is just the information you need.

Unfortunately, while Hugs prints the list of instances of a class in 
response to :i, GHCi does not. It only prints the class definition -- 
which, for my students, contains no useful information. For that reason 
alone, I stuck with Hugs last year.

Of course, later in the course there is no problem in introducing GHC as 
well. Students coping well are happy to learn there is a compiler 
available too, while those who are struggling can stay with Hugs 
throughout the course. I demonstrated GHC in order to show them 
wxHaskell (which was very popular with the students), but I didn't 
REQUIRE them to use it.

How about changing the behaviour of :i, Simon, so I can use GHCi 
throughout next year?

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


[Haskell-cafe] Information given by :info (Was: Some random newbie questions)

2005-01-10 Thread Henning Thielemann

On Mon, 10 Jan 2005, John Hughes wrote:

 What IS useful, right from the beginning, is the list of instances. What 
 are Num types? Oh, integers and reals.  What are Show types? Oh, pretty 
 much everything. Particularly when debugging missing instance errors, 
 this is just the information you need.

Good idea! What I also would like to see is the Haddock documentation
string of a function printed by :info or some other command.

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


[Haskell-cafe] Re: Guards

2005-01-10 Thread Henning Thielemann

On Sat, 8 Jan 2005, Lemming wrote:

 Jon Cast wrote:
 
  Absolutely.  In Haskell's syntax, if-then-else-if interacts badly with
  do notation, and Haskell lacks a direct analogy to Lisp's cond.
  
  case () of
() | p1 - e1
   | p2 - e2
   ...
 
 No problem:
 
 select :: a - [(Bool, a)] - a
 select def = maybe def snd . List.find fst

Alternatively:
 select def = fromMaybe def . lookup True

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


Re: [Haskell-cafe] Hugs vs GHC (again) was: Re: Some random newbiequestions

2005-01-10 Thread Ketil Malde
Marcin 'Qrczak' Kowalczyk [EMAIL PROTECTED] writes:

  - Do the character class functions (isUpper, isAlpha etc.) work
correctly on the full range of Unicode characters?

 It's not obvious what the predicates should really mean, e.g. should
 isDigit and isHexDigit include non-ASCII digits or should isSpace
 include non-breaking space characters.

I think perhaps the answer is all of the above.  The functions could
be defined in multiple modules, so that 'ASCII.isSpace' would match
the normal space character only, while 'Unicode.isSpace' could match
all the weird and wonderful stuff in the standard.

I also have the feeling that 'String' and/or 'Char' should be classes
rather than data types (perhaps with 'String' built on top of a more
general 'Sequence' type?)  Ideally, you could treat an array as well
as a list as a string.

JM$0.02

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants

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


Re: [Haskell-cafe] Re: Some random newbie questions

2005-01-10 Thread Sebastian Sylvan
On Mon, 10 Jan 2005 10:15:57 +0100, John Hughes [EMAIL PROTECTED] wrote:

 snip
 How about changing the behaviour of :i, Simon, so I can use GHCi
 throughout next year?

Agreed. GHCi also produces what can be perceived as odd output when
typing, for instance, :i +
-- + is a method in class Num
infixl 6 +
(+) :: forall a. (Num a) = a - a - a

What I'm referring to is of course the forall a. which confuses newcomers.

Personally, I'd also like a graphical interface with similar features
as winhugs (mainly the recently opened files list and a graphical
way to alter settings), but maybe that's just me...

/S
-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Information given by :info (Was: Some random newbie questions)

2005-01-10 Thread Sebastian Sylvan
On Mon, 10 Jan 2005 10:30:46 +0100 (MEZ), Henning Thielemann
[EMAIL PROTECTED] wrote:
 What I also would like to see is the Haddock documentation
 string of a function printed by :info or some other command.
 

Now _that_ would be truly useful.

/S

-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Using Haskell as a database

2005-01-10 Thread Dmitri Pissarenko
Hello!

I am thinking about writing a system, using which it is possible to store
information about the structure of a bureaucratic system. 
  
Coarse-grained features of the program include: 
  
1) The program should allow the user to enter the hierarchy (like: authority X
has a board of Y members, each of them has Z departments under his/her control
etc) of a governmental organization 
  
2) The program should visualize the hierarchy in form of a tree 
  
3) It should be possible to enter information about what areas of public
administration a particular civil servant is responsible for. In other words:
If things go wrong in some domain, controlled by the government, the user
should be able to figure out, who is responsible for that mess. 
  
My first idea was to use a relational database for storing this information.

However, a relational database may be inefficient due to the complexity of the
data structure.

At the moment, I think that it makes more sense to store the data in form of
facts (not tables as in relational database).

I mean that one is able to enter statements like (this is PROLOG syntax)

isOrganization(X).
hasBoard(X, Members) :- isOrganization(X),
isList(Members).
civilServant(X).
isResponsibleFor(X, Y) :- civilServant(X),
domain(Y).

and then run queries, using which one can find out, which organizations are
there, what members they have etc.

Can one do this in Haskell?

Thanks in advance

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


Re: [Haskell-cafe] Using Haskell as a database

2005-01-10 Thread Mark Carroll
On Mon, 10 Jan 2005, Dmitri Pissarenko wrote:
(snip)
 At the moment, I think that it makes more sense to store the data in form of
 facts (not tables as in relational database).
(snip)

A Haskell binding for something some of the stuff at
http://www.ai.sri.com/~gfp/ might be useful?

I'd often wondered about implementing something that
looked like GFP to the user, but had an ODBC backend.

-- Mark

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


RE: [Haskell-cafe] Implementing computations with timeout

2005-01-10 Thread Simon Marlow
On 07 January 2005 22:17, Tomasz Zielonka wrote:

 On Fri, Jan 07, 2005 at 11:00:27PM +0100, Tomasz Zielonka wrote:
 Hmmm, TMVar's seem to be significantly (ie. 6 times) faster than
 MVars in some simple tests :) 
 
 Is it expected?
 
 If it is, we can reimplement MVars using STM, when STM becomes stable
 :) 

No, TMVars are quite a bit slower than MVars if you use the basic
takeMVar/putMVar ops.  However, if you use the safer withMVar/modifyMVar
combinators, then you'll probably find that performance is about the
same. A simple test I did comparing TChan with Chan came up with roughly
the same performance, and STM isn't really tuned yet.

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


RE: [Haskell-cafe] Implementing computations with timeout

2005-01-10 Thread Simon Marlow
On 07 January 2005 20:00, Sebastian Sylvan wrote:

 On Fri, 7 Jan 2005 20:56:42 +0100, Sebastian Sylvan
 [EMAIL PROTECTED] wrote:
 On Fri, 07 Jan 2005 15:31:10 +0200, Einar Karttunen
 ekarttun@cs.helsinki.fi wrote:
 Hello
 
 What is the best way of doing an computation with a timeout?
 
 I like the approach taken in  Tackling the ackward squad:
 
 
 I should also state that this isn't safe when it comes to asynchronous
 exceptions.
 If one were to raise an exception in a timeout'd computation it would
 simply abort the takeMVar which means the two child processes won't
 get killed.

Yes, making a timeout combinator that (a) can be nested and (b) is
invisible with respect to asynchronous exceptions is quite a challenge.
I'm not sure that we managed to do it.  STM will almost certainly make
it easier, though.

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


RE: [Haskell-cafe] Re: Hugs vs GHC (again) was: Re: Some randomnewbiequestions

2005-01-10 Thread Simon Marlow
On 08 January 2005 08:09, Aaron Denney wrote:

 On 2005-01-07, Simon Marlow [EMAIL PROTECTED] wrote:
  - Can you use (some encoding of) Unicode for your Haskell source
files? I don't think this is true in any Haskell compiler right
 now. 
 
 I assume this won't be be done until the next one is done...

Not necessarily; GHC doesn't use the standard IO library for reading
source files.

  - Can you do String I/O in some encoding of Unicode?  No Haskell
compiler has support for this yet, and there are design decisions
to be made.  Some progress has been made on an experimental
prototype (see recent discussion on this list).
 
 Many of the easy ways to do this that I've heard proposed make the
 current hacks for binary IO fail.

Making hacks fail isn't necessarily a bad thing :-)

 IMHO, we really, really, need a
 standard, supported way to do binary IO.

I agree, but I think it should be part of a larger redesign of the IO
library.  The streams proposal includes binary I/O, by the way.

I'm not keen to provide binary IO on top of the existing IO library, and
then to have Unicode as a layer on top of that.  Performance will be
terrible.  It needs to be designed properly from the ground up.

 If I can read in and output
 octets, then I can implement unicode handling on top of that.  In fact
 it would let a bunch of the proposed ideas for unicode support can
 be implemented in pure haskell and have API details hashed out and
 polished.
 
 For unix, there are couple different tacks one could take.  The locale
 system is standard, and does work, but is ugly and a pain to work
 with. In particular, it's another (set of) global variables.  And
 what do you do with a character not expressible in the current locale?
 
 I'd like to possibility of different character sets for different
 files, for example.

Not a problem.  Have you looked at the streams proposal?

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


Re: [Haskell-cafe] Hugs vs GHC (again) was: Re: Some random newbiequestions

2005-01-10 Thread Marcin 'Qrczak' Kowalczyk
Jrmy Bobbio [EMAIL PROTECTED] writes:

 Once this is agreed, it would be easy to make scripts which generate
 C code from UnicodeData.txt tables from Unicode. I think table-driven
 predicates and toUpper/toLower should better be implemented in C;
 Haskell is not good at static constant tables with numbers.

 Sebastien Carlier already wrote this for hOp, see :
 http://etudiants.insia.org/~jbobbio/hOp/Gen_wctype.hs

And I've done a similar thing for my language Kogut some time ago:
http://cvs.sourceforge.net/viewcvs.py/kokogut/kokogut/runtime/make-char-tables.in?view=markup
http://cvs.sourceforge.net/viewcvs.py/kokogut/kokogut/lib/Core/Kokogut/Characters.ko?view=markup

Let's see how these separately developed interpretations of predicates differ
(mine also have different names and there are a few more):

|Sebastien's| mine
 ---+---+--
  alnum | L* N* | L* N*
  alpha | L*| L*
  cntrl | Cc| Cc Zl Zp
  digit | N*| Nd
  lower | Ll| Ll
  punct | P*| P*
  upper | Lu| Lt Lu
  blank | Z* \t\n\r | Z*(except U+00A0 U+2007 U+202F) \t\n\v\f\r U+0085

Note that the interpretation of digit differs from both C and
Haskell 98 which specify it to be ASCII-only. Actually I have
ASCII-only variants of IsDigit parametrized by the number base.

-- 
   __( Marcin Kowalczyk
   \__/   [EMAIL PROTECTED]
^^ http://qrnik.knm.org.pl/~qrczak/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Hugs vs GHC (again) was: Re: Some randomnewbiequestions

2005-01-10 Thread Andre Pang
Simon Marlow wrote:
Not a problem.  Have you looked at the streams proposal?
Is there a Wiki page or URL with the steram proposal?
--
% Andre Pang : trust.in.love.to.save  http://www.algorithm.com.au/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Hugs vs GHC (again) was: Re: Some randomnewbiequestions

2005-01-10 Thread Ben Rudiak-Gould
Andre Pang wrote:
 Is there a Wiki page or URL with the steram proposal?
It's here:
   http://www.haskell.org/~simonmar/io/System.IO.html
-- Ben
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe