Re: threaded red-black tree

2003-09-15 Thread andrew cooke

this might help:
http://www.cs.kent.ac.uk/people/staff/smk/redblack/Untyped.hs

andrew

Lex Stein said:


 Hi, No one responded to my question several weeks ago about a purely
 functional implementation of a threaded, red-black tree. My message was
 sent about the same time as that flurry of silly emails about how to
 respond to homework questions. Was my message not responded to because it
 was classified as a homework question? I assure you this is officework,
 not homework. I ended up porting Okasaki's red-black tree implementation;
 hacking it apart with a bunch of mutation for the threading of the list
 through the tree. However, I'm still missing a deletion function and I
 haven't been able to find a prototype (Okasaki's red-black tree module
 lacks delete). My study of the RB-tree deletion routine in CLR hasn't yet
 yielded an adaptation for a functional environment. Any advice would be
 much appreciated.

 Thanks,
 Lex

 --
 Lex Stein http://www.eecs.harvard.edu/~stein/
 [EMAIL PROTECTED]cell: 617-233-0246

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




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


Read file problems

2003-09-15 Thread Frederic BELLOC
HI,
I have a recurrent probleme with function readFile and Monad :
it is that i try to get a line, transform it  and stock it in a list
and what i want is that function return me the list.
But hugs say me that in

readFile my_file = \s - map cons_line (lines s)
readFile is a IO String type but is used here as [[Char]] type...
and i don't know what to do... 

Ghc say me that is the lambda abstraction that fails with 
map cons_line (lines s) , he couldn't match IO against [] !

Help me please, i understand well (i hope) how Monad work but here i don't see
a solution.

Sorry for my poor english but i'm already a student.

Thanks for all.
-- 
C, socks and sun ;-)
and haskell bugs :-(

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


Re: Instance checking and phantom types

2003-09-15 Thread Sven Panne
Nick Name wrote:
Hi all, I have an example wich I don't understand:
First of all, let's rename the constructors and types a bit to make
things clearer add the instance in question, and remove the type
signatures:

module Main where
class C t
data T = MkT
instance C T
instance C ()
data C t = T1 t = MkT1

f1 = MkT1

data C t = T2 t = MkT2 t

f2 = MkT2 ()

Then we can easily ask GHC:


[EMAIL PROTECTED]:~ ghci -v0 Main.hs
*Main :i T1 MkT1 f1 T2 MkT2 f2
-- T1 is a type constructor, defined at Main.hs:8
data (C t) = T1 t = MkT1
-- MkT1 is a data constructor, defined at Main.hs:8
MkT1 :: forall t. T1 t
-- f1 is a variable, defined at Main.hs:10
f1 :: forall t. T1 t
-- T2 is a type constructor, defined at Main.hs:12
data (C t) = T2 t = MkT2 t
-- MkT2 is a data constructor, defined at Main.hs:12
MkT2 :: forall t. (C t) = t - T2 t
-- f2 is a variable, defined at Main.hs:14
f2 :: T2 ()

The first function, f1, is accepted both by hugs and ghc, unlike the 
second wich is rejected.

Why does this happen? Shouldn't f1 be rejected with no instance C ()
The reason is buried in

   http://haskell.org/onlinereport/decls.html#sect4.2.1

In a nutshell: The context in datatype declarations has only an effect for
the *data* constructors of that type which use the type variables mentioned
in the context. Contexts have no effect for the *type* constructor. IIRC the
reason for this design decision was that contexts in type signatures should
always be explicit.
Cheers,
   S.
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Instance checking and phantom types

2003-09-15 Thread Sven Panne
Nick Name wrote:
Got it ;) Thanks for prompt reply. What does should always be explicit 
mean? Is there a notion of explicit context that I should know?
What I meant was the fact that you always have to write down *all* contexts
involved in a type signature. Nothing is inherited under the hood by
contexts in datatype declarations.
Cheers,
   S.
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe