Re[4]: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Bulat Ziganshin
Hello Simon,

Friday, July 21, 2006, 7:46:15 AM, you wrote:

> | ps: you successfully going through all the standard Haskell troubles
> in
> | this area :)  seems that making FAQ about using ST monad will be a
> | good idea :)

> Indeed. If someone would like to start one, a good place for it would be
> GHC's collaborative-documentation Wiki
> http://haskell.org/haskellwiki/GHC#Collaborative_documentation

they are not ghc-specific, afaik


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


RE: Re[2]: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Simon Peyton-Jones

| ps: you successfully going through all the standard Haskell troubles
in
| this area :)  seems that making FAQ about using ST monad will be a
| good idea :)

Indeed. If someone would like to start one, a good place for it would be
GHC's collaborative-documentation Wiki
http://haskell.org/haskellwiki/GHC#Collaborative_documentation

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


Re: Re[2]: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Udo Stenzel
Chad Scherrer wrote:
> But why should this...
> 
> >sumArrays [] = error "Can't apply sumArrays to an empty list"
> >sumArrays (x:xs) = runSTArray (result x)
> >where
> >result x = do x0 <- thaw x
> >  mapM_ (x0 +=) xs
> >  return x0
> 
> work differently than this...
> 
> >sumArrays' [] = error "Can't apply sumArrays to an empty list"
> >sumArrays' (x:xs) = runSTArray result'
> >where
> >result' = do x0 <- thaw x
> > mapM_ (x0 +=) xs
> > return x0
> 
> Are the types of (result x) and result' not exactly the same?

It's the monmorphism restriction, again.  Because result' doesn't look
like a function, a monomorphic type is inferred for it.  runST[U]Array
of course doesn't want a monomorphic type.  It's got nothing to do with
boxed vs. unboxed arrays (I think, I can't be bothered to test it right
now).

There are at least four ways out:

- make result' a function, either as in the first example above or by
  supplying a dummy () argument
- declare the correct polymorphic type for result'
- inline result'
- (GHC only) compile with -fno-monomorphism-restriction

Yes, it's a bit cumbersome.  Imperative code is supposed to be
cumbersome, after all.  :)


Udo.
-- 
They seem to have learned the habit of cowering before authority even
when not actually threatened.  How very nice for authority.  I decided
not to learn this particular lesson.
-- Richard Stallman


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


[Haskell-cafe] Re: rigid variables

2006-07-20 Thread Rodney D Price


Thanks for the responses.  The semantics of check as described the
"Data Invariants" paper on STM are really close to what I am looking
for.  Unfortunately, that work is not in GHC yet, so I'm attempting my
own poor substitute (below).  I have a store that is to be accessed by
other threads, and I want to throw an error under certain conditions.
(The names below are borrowed from the "Scheme in 48 Hours"
tutorial.)  In reality I'm looking for an inconsistent store, but for
simplicity's sake I've just put in a standard read operation below.
Is there an easier way?

Thanks,

-Rod


--
module Store where

import Control.Monad.Error
import Control.Concurrent.STM

data StoreError = DoesNotExist String
| Default String

instance Error StoreError where
noMsg  = Default "Store error"
strMsg = Default

type ThrowsError = Either StoreError

type IOThrowsError = ErrorT StoreError IO

type Store a = TVar [ (String, TVar a) ]


-- read from the store
getSTM :: String -> Store a -> STM (ThrowsError a)
getSTM name store = do
st <- readTVar store
case lookup name st of
Nothing -> return (Left $ DoesNotExist name)
Just rd -> readTVar rd >>= return . Right

get :: String -> Store a -> IOThrowsError a
get name store = do
d <- liftIO $ atomically $ getSTM name store
case d of
Left err -> throwError err
Right d' -> return d'

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


Re: [Haskell-cafe] doubt on gui

2006-07-20 Thread Duncan Coutts
On Thu, 2006-07-20 at 18:09 +0300, Alvaro Galan wrote:
> Hi, im almost new in haskell world, but im trying to do a simple
> graphical interface for a small program, i developed the program under
> winhugs, and now i want to develop the gui also with it, but all the
> libraries and kits that i download from the haskell page is either for
> ghc  or need to be make or stuff, my question, is or isnt a library or
> something that i can download, then import and use it on winhugs
> without compile, download a ton of things, etc etc?
>  is there some way of developing a very easy gui (based on radio
> buttons) with normal librarys on winhugs?, or its compulsory get ghc?

I don't think that there are any GUI libs like that that work with hugs.
There are some graphics libraries (like HGL) that work with Hugs, but it
doesn't include features like radio buttons etc.

So for a GUI, I'd recommend GHC and either Gtk2Hs or wxHaskell.

Duncan

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


Re: Re[2]: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Chad Scherrer

Ok, I see now why the return is necessary. For now I'll switch to
boxed arrays until I get the rest of this down better.

But why should this...


sumArrays [] = error "Can't apply sumArrays to an empty list"
sumArrays (x:xs) = runSTArray (result x)
where
result x = do x0 <- thaw x
  mapM_ (x0 +=) xs
  return x0


work differently than this...


sumArrays' [] = error "Can't apply sumArrays to an empty list"
sumArrays' (x:xs) = runSTArray result'
where
result' = do x0 <- thaw x
 mapM_ (x0 +=) xs
 return x0


Are the types of (result x) and result' not exactly the same?


--

Chad Scherrer

"Time flies like an arrow; fruit flies like a banana" -- Groucho Marx
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Bulat Ziganshin
Hello Chad,

Thursday, July 20, 2006, 9:38:43 PM, you wrote:

> I suppose the same holds for runSTUArray, right? But this still gives
> me that same error, about being less polymorphic than expected.

there is well-known problem with that _unboxed_ arrays aren't
polymorphic. Oleg Kiselyov proposed solution to that problem that i implemented
in ArrayRef library (read 
http://www.haskell.org/pipermail/haskell-cafe/2004-July/006400.html
and http://haskell.org/haskellwiki/Library/ArrayRef)

this code compiles (i've also fixed pair of other problems):

import Data.ArrayBZ.IArray
import Data.ArrayBZ.ST


(+=) x y = let updateX i = do xi <- readArray x i
  writeArray x i (xi + y!i)
   in  sequence_ . map updateX $ indices x

sumArrays [] = error "Can't apply sumArrays to an empty list"
sumArrays (x:xs) = runSTUArray (result x)
where
result x = do x0 <- thaw x
  mapM_ (x0 +=) xs
  return x0

ps: you successfully going through all the standard Haskell troubles in
this area :)  seems that making FAQ about using ST monad will be a
good idea :)


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] Re: [Haskell] rigid variables

2006-07-20 Thread Robert Dockins

[moved to cafe]

On Jul 20, 2006, at 12:48 PM, Rodney D Price wrote:

I've gotten this sort of error several times, which mysteriously  
disappears

when I add more functions to the code:

storeError.hs:13:38:
Couldn't match expected type `a' (a rigid variable)
   against inferred type `String'
  `a' is bound by the type signature for `throwError'
at 
  Expected type: a
  Inferred type: String
In the first argument of `return', namely `msg'
In the call (return msg)

(This is GHCi.)  The code is below.  The type variable a can't be  
bound to
String, obviously, but a relative novice like myself has no idea  
why.  Can

someone tell me?

Thanks,

-Rod

--
module Store where

import Control.Monad.Error
import Control.Concurrent.STM

data StoreError = Default String

instance Error StoreError where
noMsg  = Default "Store error"
strMsg = Default

instance MonadError StoreError STM where
throwError (Default msg) = return msg



Lets take a look here at the definition of MonadError from  
Control.Monad.Error:


class Monad m => MonadError e m | m -> e where
throwError :: e -> m a
catchError :: m a -> (e -> m a) -> m a


In the signature for 'throwError' there are three type variables: e,  
m and a.  e and m are bound by the instance declaration, but a is  
free.  In Haskell the rule is that free variables are implicitly  
bound with a universal quantifier.  So, the type for throwError can  
be regarded as,


throwError :: forall a. e -> m a,  for some concrete choices of  
e and m which are determined by the instance.


The forall means that a user of this function can put any type there  
that he likes.  In other words, the monadic action created by  
'throwError', when executed, evaluates to _a value of any type at  
all_ (yes, I know the terminology is a little loose here).  That  
means you can't just 'return msg', which has type 'm String' because  
a user might have used throwError to create an action of type 'm  
Int', for example.  In fact, you won't really be able to return  
anything at all, because there isn't any way to write a program that  
can generate a value of any unknown type.  This should hopefully  
correspond to your intuition about what throwing an exception does.


The error generated by the typechecker basically tells you that the  
function you have written is not polymorphic enough.  It has type  
'StoreError -> STM String' rather than 'forall a. StoreError -> STM  
a' as it ought.


I think perhaps you have misunderstood how MonadError is used.  The  
idea is to expose to users a particular non-local control flow  
construct (throw/catch style exceptions) by hiding all the stuff  
necessary for that inside the monad plumbing.  Usually, whoever  
writes the monad itself will provide the necessary instances.  It's  
often not possible to write instances like this by using the external  
API of the monad.  This is particularly the case for the abstract  
monads available in GHC (IO, ST, and STM).


In short, I don't think you'll be successful in writing a  
'MonadError' instance for STM that has the customary semantics.  What  
you may be looking for is the ErrorT monad transformer, which will  
let you layer error handling over STM.  It's hard to know with what  
info you've provided here.  If you give a few more details on what  
you're trying to accomplish, someone may be able to give you a push  
in the correct direction.




Rob Dockins

Speak softly and drive a Sherman tank.
Laugh hard; it's a long way to the bank.
  -- TMBG



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


Re: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Chad Scherrer

Hi,


The short answer: use
runST (long expression)
rather than
runST $ long expression

when it comes to higher-ranked functions such as runST.


I suppose the same holds for runSTUArray, right? But this still gives
me that same error, about being less polymorphic than expected.

(+=) x y = let updateX i = do xi <- readArray x i
 writeArray x i (xi + y!i)
  in  sequence_ . map updateX $ indices x

sumArrays [] = error "Can't apply sumArrays to an empty list"
sumArrays (x:xs) = runSTUArray result
   where
   result = do x0 <- thaw x
   mapM_ (x0 +=) xs
   x0



--

Chad Scherrer

"Time flies like an arrow; fruit flies like a banana" -- Groucho Marx
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Why is there no splitBy in the list module?

2006-07-20 Thread Jon Fairbairn
On 2006-07-13 at 10:16BST I wrote:
> Hooray!  I've been waiting to ask "Why aren't we asking what
> laws hold for these operations?"

Having thought about this for a bit, I've come up with the
below. This is intended to give the general idea -- it's not
polished code, and I'm not at all wedded to the names I've
used, and it almost certainly should be split up.

> module Parts (parts, fromParts, contiguousParts, segmentsSatisfying) where 
> import List (groupBy)

> parts p = map hack . groupBy sameSide . map (predicateToEither p)
> fromParts = concat . map fromEither

  Now we should have fromParts . parts p ⊑ (id:: [a]->[a])
  In particular, it should be possible to apply a function
  to all the Right parts, and then reconstruct the list with
  the Left parts left alone.

  for example

  fromParts . mapRight uc_first . parts Char.isAlpha $ "A random list of 
words\non lines"
  where uc_first [] = []
uc_first (a:as) = Char.toUpper a:as

  => "A Random List Of Words\nOn Lines"


> contiguousParts p l = [a | Right a <- parts p l]

  so words = contiguousParts Char.isAlphaNum

> segmentsSatisfying predicate
> = concat . map dropSeps . parts predicate
>   where dropSeps e
> = case e of
> Left x -> map (const []) $ tail x
> Right r -> [r]

  So 

  lines = segmentsSatisfying (/= '\n') 

  ... but the tail in the definition of segmentsSatisfying
  makes me uneasy.


  needing the function `hack` suggests that the definition of
  parts is written badly

> hack (Left x:rest) = Left (x: map (\(Left x) -> x) rest)
> hack (Right x:rest) = Right (x: map (\(Right x) -> x) rest)

  what follows must surely exist in a library somewhere?
  I'd expect it to be called Either...

> predicateToEither :: (a -> Bool) -> a -> Either a a
> predicateToEither p x = if p x
> then Right x
> else Left x

> sameSide (Left _) (Left _) = True
> sameSide (Right _) (Right _) = True
> sameSide _ _ = False

> fromEither (Left x) = x
> fromEither (Right x) = x

> liftE f1 f2 = either (Left . f1) (Right . f2)

> mapRight f = map (onRight f)

> onRight f = liftE id f

> mapLeft f = map (onLeft f)
> onLeft f = liftE f id


  we could do some of half of those using this:

> instance Functor (Either a) where
> fmap f (Right a) = Right (f a)
> fmap f (Left l) = Left l


  Is a Monad instance any use?

> instance Monad (Either a) where
> Right a >>= f = f a
> Left l >>= f = Left l
> return = Right


-- 
Jón Fairbairn  Jon.Fairbairn at cl.cam.ac.uk


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


[Haskell-cafe] doubt on gui

2006-07-20 Thread Alvaro Galan

Hi, im almost new in haskell world, but im trying to do a simple
graphical interface for a small program, i developed the program under
winhugs, and now i want to develop the gui also with it, but all the
libraries and kits that i download from the haskell page is either for
ghc  or need to be make or stuff, my question, is or isnt a library or
something that i can download, then import and use it on winhugs
without compile, download a ton of things, etc etc?
is there some way of developing a very easy gui (based on radio
buttons) with normal librarys on winhugs?, or its compulsory get ghc?


Kind Regards.
Alvaro.


--
It's only Rock'n'Roll (..but I like it)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Chad Scherrer

Whoa. That changes everything I thought I knew about ($). Come to
think of it, one of the examples that does work it written
main = print $ runST f
where f is defined separtely. So that's consistent.

I'll take a look at the references. Thanks!



Indeed. The short answer: use
runST (long expression)
rather than
runST $ long expression

when it comes to higher-ranked functions such as runST.
A longer answer:
http://www.haskell.org/pipermail/haskell-cafe/2004-December/008062.html

> let me know what i need to read to fix it myself
MLF (see Daan Leijen, A. Loeh, `Qualified types for MLF', ICFP05)



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


Re: [Haskell-cafe] trace function

2006-07-20 Thread Malcolm Wallace
Alexander Vodomerov <[EMAIL PROTECTED]> wrote:

> main = do
>   putStrLn "xxx"
>   return (trace "yyy" ())
>   putStrLn "zzz"
> 
> only xxx and zzz is displayed. yyy is missing.

This is because you never demanded the value of (trace "yyy" ()), so it
was never computed.  The joys of laziness!  To force its evaluation try

  main = do
putStrLn "xxx"
() <- return (trace "yyy" ())
putStrLn "zzz"

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


Re: [Haskell-cafe] RE: ANN: System.FilePath 0.9

2006-07-20 Thread David Roundy
On Wed, Jul 19, 2006 at 03:16:48AM +0100, Neil Mitchell wrote:
> >I tried to export a minimal set of operations that seem to me sufficient
> >for everything not very platform-specific (though I am interested in
> >counterexamples):
> 
> Anything to do with file extensions? Its also important (I feel) for
> people to have easy access to common operations, but I guess that is a
> design decision.

Personally, I don't care for the idea of doing anything with file
extensions.  Handling file extensions is a bit tricky, in the sense
that it's ambiguous what the application actually wants, and so
(unlike the other parts of the FilePath library, which reflect how the
OS sees a FilePath) there's no real solution.  e.g. is foo.ps.gz a .ps
file, or just a .gz file or a .ps.gz file? I can open it with gv (a
postscript viewer), but can't open any other .gz file with gv.

In general, I feel that file extensions are most often useless, and a
better approach to almost any use of them would be something like
libmagic to identify files, or access to mailcap, for instance.
Perhaps as part of a mime-support package, which would have something
like:

identifyMimeType :: FilePath -> IO String -- or ADT for mime types
getMimeHandler :: FilePath -> IO (IO FilePath)
-- te above returns a wrapped function that calls the mime handler for
-- specified file

Note that the latter is actually the more portable, as it wouldn't
even need to use MIME as an intermediate, but could look up the
handler based on file extension on platforms where that's
appropriate.
-- 
David Roundy
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] trace function

2006-07-20 Thread Neil Mitchell

Hi,

Either one of these will work:

main = do
putStrLn "xxx"
x <- return (trace "yyy" ())
x `seq` putStrLn "zzz"

main = do
putStrLn "xxx"
trace "yyy" (return ())
putStrLn "zzz"


This works fine, the problem is that trace is defined to output the
first parameter before returning the second. In the case of return ()
the () is never evaluated, hence the item is never generated, and the
trace is not fired. Adding a seq to the result gets the trace going.

This just shows how fragile trace is! However, if you use it in a real
situation, rather than just a play one like this, it will probably
work for you.

Thanks

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


Re: [Haskell-cafe] Opening a file that another process is writing

2006-07-20 Thread Bulat Ziganshin
Hello Maurício,

Thursday, July 20, 2006, 1:22:01 AM, you wrote:

>I want to open for reading a log file that another process is locking
> for write. I know it's possible, since 'cat' and 'vim' can read that 
> file (but not edit it, of course). How can I do that in Haskell? 
> 'openFile' says "permission denied".

(untested) i think you should open it in shared mode, that is
impossible via openFile. but you can open Fd using low-level
c_open call and then use fdToHandle procedure


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] RE: problems with receiving mail lists

2006-07-20 Thread Simon Marlow
Apparently Mailman was stuck, I've restarted it and it seems to be
working again.  Noone's account has been disabled, as far as I can tell.

Cheers,
Simon

On 20 July 2006 06:18, Bulat Ziganshin wrote:

> Hello Simon,
> 
> Simon, you are administrator of many haskell mail lists, so i wrote to
> you. last day i don't receive messages in these mail lists.
> investigating the problem, i found on haskell-cafe subscription page
> that there are some problems in mail delivery to my address. i'm not
> 100% sure but i think that it is because gmail server last days work
> too slow and in many cases login to aborts because of timeouts.
> moreover, i think that the same problem with receiving messages from
> haskell mail lists may expose other gmail users
> 
> i propose to temporarily increase timeouts of message delivery system
> which serves these mail lists. may be there is other solutions
> 
> please duplicate your message to cafe too, because i'm not sure that
> i will receive it directly
> 
> ps: and question to other gmail users - are you had problems with
> receiving email? may be it's some local problem?

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


[Haskell-cafe] test message

2006-07-20 Thread Simon Marlow
Trying to diagnose problems with mailing lists...
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] The History of Haskell

2006-07-20 Thread Maarten Hazewinkel

Simon and partners,

Thank you for this paper.

As a relative newcomer to Haskell, quite few topics on the mailing
lists went right past me. Now that I've read this paper a can at least
understand generally what most topics are about.

I'd definitely recommend this as reading material to anyone right
after they know a bit about the basic language from a tutorial. It
helps place the basic Haskell language in both its historical context,
and in the current Haskell universe with its miriad extensions and
tools.

Thanks again,

Maarten

On 7/14/06, Simon Peyton-Jones <[EMAIL PROTECTED]> wrote:

Friends,

Phil Wadler, John Hughes, Paul Hudak and I have been writing a paper
about the

The History of Haskell

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


[Haskell-cafe] problems with receiving mail lists

2006-07-20 Thread Bulat Ziganshin
Hello Simon,

Simon, you are administrator of many haskell mail lists, so i wrote to
you. last day i don't receive messages in these mail lists.
investigating the problem, i found on haskell-cafe subscription page
that there are some problems in mail delivery to my address. i'm not
100% sure but i think that it is because gmail server last days work
too slow and in many cases login to aborts because of timeouts.
moreover, i think that the same problem with receiving messages from
haskell mail lists may expose other gmail users

i propose to temporarily increase timeouts of message delivery system
which serves these mail lists. may be there is other solutions

please duplicate your message to cafe too, because i'm not sure that
i will receive it directly

ps: and question to other gmail users - are you had problems with
receiving email? may be it's some local problem?

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

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


[Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread tpledger
Chad Scherrer wrote:
> x = runST $ return 1
>
> y = runST $ do {r <- newSTRef 1; readSTRef r}
>
> Neither of these works in ghci

x = runST (return 1)

y = runST (do {r <- newSTRef 1; readSTRef r})

The escaping s is something to do with rank 2 polymorphism. 
(Search for "rank" in the ghc user guide, for example.)

The hassle is that runST must always be applied to an
argument (e.g. not passed to ($)), and a benefit is that
you're protected from using an STRef you created in the
context of one runST, in the context of another runST.

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


[Haskell-cafe] REALLY simple STRef examples

2006-07-20 Thread Chad Scherrer

I've looked around at the various STRef examples out there, but still
nothing I write myself using this will work. I'm trying to figure out
how the s is escaping in really simple examples like

x = runST $ return 1

y = runST $ do {r <- newSTRef 1; readSTRef r}

Neither of these works in ghci - they both say

:1:0:
   Inferred type is less polymorphic than expected
 Quantified type variable `s' escapes
 Expected type: ST s a -> b
 Inferred type: (forall s1. ST s1 a) -> a
   In the first argument of `($)', namely `runST'
   In the definition of `it':
  ...

I thought maybe I needed to replace 1 with (1 :: Int) so the state
representation didn't force the type, but it still gives the same
result.

Can someone point me to the simplest possible runST example that
actually works? Thanks!

--

Chad Scherrer

"Time flies like an arrow; fruit flies like a banana" -- Groucho Marx
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] trace function

2006-07-20 Thread tpledger
Alexander Vodomerov wrote:
> import Debug.Trace
>
> main = do
>   putStrLn "xxx"
>   return (trace "yyy" ())
>   putStrLn "zzz"
>
> only xxx and zzz is displayed. yyy is missing.
> Why trace is not working?

Nothing uses the value of (trace "yyy" ()), so it is never
evaluated.

Try this instead, which uses the value for a pattern match:

() <- return (trace "yyy" ())

Or this, which makes the trace part of the sequence of IO
actions:

trace "yyy" (return ())

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


[Haskell-cafe] Opening a file that another process is writing

2006-07-20 Thread Maurício

  Hi,

  I want to open for reading a log file that another process is locking 
for write. I know it's possible, since 'cat' and 'vim' can read that 
file (but not edit it, of course). How can I do that in Haskell? 
'openFile' says "permission denied".


  Thanks,
  Maurício

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


[Haskell-cafe] trace function

2006-07-20 Thread Alexander Vodomerov
  Hello!

The function trace is supposed to write debug messages to console.
However, when I trying to run the following program

import Debug.Trace

main = do
  putStrLn "xxx"
  return (trace "yyy" ())
  putStrLn "zzz"

only xxx and zzz is displayed. yyy is missing.
Why trace is not working?

PS. GHC-6.4.2, Debian Linux on x86.

With best regards,
   Alexander.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] RE: ANN: System.FilePath 0.9

2006-07-20 Thread Neil Mitchell

Hi,


> In this library proposal, there are a bunch of "xxxDrive" functions .. 
[remove them]
I strongly agree about this.


I have decided you are right, on Windows getDrive x can be written simply as:

getDrive x | isRelative x = ""
  | otherwise = head (getDirectories x)

And given that people probably shouldn't be playing with drives
anyway, if they do want to, they can do a bit more work. All the drive
related functions and therefore removed from the interface.

I have also added a canonicalPath function, support for spotting
file\con as invalid and fixing it, support for \\?\ paths (if you
don't know what they are, don't look it up, they are quite painful!)
and a few very obscure corner cases which broke some of the
properties.

Anyone have another other thoughts or comments?

Thanks

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


[Haskell-cafe] Re: Compiling ghc for using STM

2006-07-20 Thread Simon Marlow

Duncan Coutts wrote:


I believe that the smp flavour of the RTS is now built by default and so
all you need to do is use it when linking a program:

ghc-6.5 -smp Foo.hs -o foo


Yes, although -smp is now the same as -threaded, so for simplicity we'll stop 
referring to -smp and just use -threaded (it'll still be accepted for backwards 
compatibility, though).


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


[Haskell-cafe] irc channel stats

2006-07-20 Thread Donald Bruce Stewart
While we're in a period of reflection, pondering the history of haskell,
I've prepared some graphs of activity on the IRC channel.

Summary: its growing much as the mailing lists are, with more than 5000
users over the past 5 years.

Full details here,
http://www.cse.unsw.edu.au/~dons/irc/

Another interesting note is that lambdabot's get more and more verbose
over time, as it provides further features. It's turning into an ide of
sorts.

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


Re: [Haskell-cafe] Re: Type-Level Naturals Like Prolog?

2006-07-20 Thread Tom Schrijvers

On Tue, 18 Jul 2006, Jared Warren wrote:


>> % defining natural numbers
>> natural(zero).
>> natural(s(X)) :- natural(X).
>>
>> % translate to integers
>> toInt(zero, 0).
>> toInt(s(X), N) :- toInt(X, Y), N is Y + 1.

> Thank you. I can now more precisely state that what I'm trying to
> figure out is: what is 's', a predicate or a data structure? If it's a
> predicate, where are its instances? If not, what is the difference
> between the type language and Prolog such that the type language
> requires data structures?

it's data structure, to be exact, it's data constructor - just like,
for example, "Just" in Haskell. Haskell requires that all data
constructors should be explicitly defined before they can be used. you
can use "Just" to construct data values only if your program declares
"Just" as data constructor with "data" definition like this:

data Maybe a = Just a | Nothing

Prolog is more liberate language and there you can use any data
constructors without their explicit declarations, moreover, there is
no such declarations anyway


[deletia]


i once said you about good paper on type-classes level programming. if
you want, i can send you my unfinished article on this topic which shows
correspondences between logic programming, type classes and GADTs


So predicates and data constructors have similar syntax but different
semantics in Prolog?


That is right. The syntax and naming are different from Haskell though. 
They are called respectively predicate and function symbols/functors, and 
written like f(x1,...,xn) rather than F x1 ... xn. Terms are made of 
possibly nested function symbols and variables, e.g.


f(f(f(a,X))) where f and a are used as function symbols

Atoms are made of a predicate symbol and terms,e.g.

p(f(f(f(a,X where p is used as a predicate symbol
  f and a are used as function symbols

Note that the same name can be used with multiple argument numbers and
both as a predicate and a function symbol.


Say, for the sake of argument, if I wanted to do
automatic translation, how would I tell which was which in a Prolog
program?


Based on the syntax. Basically the top-level symbols are predicate symbols
and the nested ones are function symbols, e.g. in a clause

p(f(X)) :-
q(h(i)),
j(k) = l(m).

p, q and '=' are predicate symbols and all the rest are function symbols.

It's probably good to read a bit about it in a proper reference. 
Wikipedia's Prolog entry lists a number of tutorials.


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


Re[2]: [Haskell-cafe] Re: Type-Level Naturals Like Prolog?

2006-07-20 Thread Bulat Ziganshin
Hello Jared,

Tuesday, July 18, 2006, 11:12:09 PM, you wrote:

>> >> % defining natural numbers
>> >> natural(zero).
>> >> natural(s(X)) :- natural(X).
>> >>
>> >> % translate to integers
>> >> toInt(zero, 0).
>> >> toInt(s(X), N) :- toInt(X, Y), N is Y + 1.
>>
>> > Thank you. I can now more precisely state that what I'm trying to
>> > figure out is: what is 's', a predicate or a data structure? If it's a
>> > predicate, where are its instances? If not, what is the difference
>> > between the type language and Prolog such that the type language
>> > requires data structures?
>>
>> it's data structure, to be exact, it's data constructor - just like,
>> for example, "Just" in Haskell. Haskell requires that all data
>> constructors should be explicitly defined before they can be used. you
>> can use "Just" to construct data values only if your program declares
>> "Just" as data constructor with "data" definition like this:
>>
>> data Maybe a = Just a | Nothing
>>
>> Prolog is more liberate language and there you can use any data
>> constructors without their explicit declarations, moreover, there is
>> no such declarations anyway
>>
> [deletia]
>>
>> i once said you about good paper on type-classes level programming. if
>> you want, i can send you my unfinished article on this topic which shows
>> correspondences between logic programming, type classes and GADTs

> So predicates and data constructors have similar syntax but different
> semantics in Prolog? Say, for the sake of argument, if I wanted to do
> automatic translation, how would I tell which was which in a Prolog
> program?

how about buying some little Prolog book? :)  prolog statements look as

phrase :- phrase, phrase, phrase.

where each phrase has syntax

predicate(data,data,data)

where data has one of the following shapes

simple
or
data(data,data,data)

where simple may be constant (any lower-cased word) or represent
variable (upper-cased word or _)

Prolog constants plays the same role as Haskell data constructors -
they can be lowest-level data items or a way to construct something
more complex from simpler things. for example, Haskell value
"Right (Nothing, Just Nothing)" can be translated to Prolog value
"right (nothing, just (nothing))"

next, Prolog is untyped language. ALL the values belongs to one common
datatype. there is no type declarations, any value can be constructed
by rules i given for 'data' (of course, you should not use variables,
only constants). if you construct 'data' using both variables and
constants - you get the pattern to match in predicates.

> "Faking it: Simulating dependent types in Haskell" certainly explains
> *one* way to simulate dependent types, but I need to justify the
> existence of type constructors in an Idealised Haskell, so I must
> understand why the implementation in Prolog does not appear to be a
> literal translation.

Haskell, unlike Prolog, has strict static typing. each value and each
variable has its type. these types are declared via 'data' statements:

data Typename = Constructor1 Subtype11 Subtype12
  | Constructor2 Subtype21 Subtype22

these statements defines correspondence between types and values -
using 'data' declarations, we can find for each value exact type to
which it belongs. for example, value "(LT, Just True)" has the
type "(Ordering, Maybe Bool)", what you can discover by finding 'data'
declarations where each of used data constructor (LT, Just, True) is defined

Haskell supports logic programming on type constructors (which are
defined on the left side of 'data' statement), not on the data
constructors (defined at the right side), but the requirement remains
- type constructors with which 'instance' definitions deal, should be
predefined in program, you can't use type constructors not defined in
some 'data' statements. because in this case you don't use data
constructors (i.e., the right side), you can use nullary types for
this purpose:

data Zero
data Succ a

is that, theoretically, possible to change Haskell so that it can use
any type constructors in instance declarations without predeclaring
them in 'data' statements? yes, that's possible. the only information
Haskell receives from these 'data' statements is type constructor
arity and if Haskell compiler will have another way to guess what is
arity - data statements can be avoided


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] RE: ANN: System.FilePath 0.9

2006-07-20 Thread Neil Mitchell

Hi


> I want to make sure a filename is valid. For example, "prn" and "con"
This is another rat's nest, so I suggest that it be dealt with
separately from the basic filepath module.  The notion of "valid" is
squishy:  It depends entirely on what you intend to do with the path.


Its a rats nest to do it properly, but some very basic idea of "does
this path have things which there is no way could possibly be in a
file" - for example c:\|file is a useful thing to have. By making it
pure, there is no risk of the result being different. I see the
isValid guarantee more as a False means it definately isn't valid,
rather than the other way round.



> In this library proposal, there are a bunch of "xxxDrive" functions
> that many Unix-oriented programmers are sure to ignore because they are
> no-ops on Unixy systems. Even on Windows, they are not very useful:

I strongly agree about this.  The temptation in path modules seems to be
to throw in everything you can think of (without specifying any of it
precisely), just in case someone finds it useful.


The drive functions stand on their own as a chunk, and are possibly
not well suited to a Posix system, but are critical for a Windows
system. Ignoring these, which would you consider worthy of removal?
Some are strictly "redundant", but quite useful - for example
isAbsolute/isRelative which are the negation of each other.

I have tried to specify the functions precisely, and I use this
specification as a test suite. Currently there are 114 properties in
this test suite, all can be seen on the haddock documentation. If you
consider any function to be ambiguously specified, please say which
one and I'll add extra tests until it gives you no suprises at all.
QuickCheck rules :)


I tried to export a minimal set of operations that seem to me sufficient
for everything not very platform-specific (though I am interested in
counterexamples):


Anything to do with file extensions? Its also important (I feel) for
people to have easy access to common operations, but I guess that is a
design decision.

Thanks

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


[Haskell-cafe] Type level logic programming terminology

2006-07-20 Thread oleg

Most systems of (first-order) logic differentiate between function
letters (aka, symbols) and predicate letters (symbols). The former are
used to build terms; the latter build atomic formulas (which can later
be combined in more complex formulas using negation, conjunction,
disjunction, and quantification):
http://plato.stanford.edu/entries/logic-classical/

Formulas like Even (succ zero) can be interpreted to be `true' or
`false' (alternatively: succeed or fail). In the atomic formula above,
Even is a predicate symbol. OTH, terms like `succ zero' (an
application of a function symbol succ to a constant zero) is not
interpreted as true or false: it just is.

In Prolog, there is likewise distinction between terms (which can be
compared and unified, but cannot 'fail') and goals. The following
gives a good introduction in the typed setting:

http://www.cs.mu.oz.au/research/mercury/information/doc-release/reference_manual_2.html

Incidentally, many Prolog systems also permit declarations of goals
and of terms (because it helps produce better code). Lambda-Prolog,
like Mercury, insists on declarations.

The distinction between terms and goals is a bit blurred in Prolog,
due to its reflection facilities: one can add a new term as a rule or
a fact (e.g., using assert), one can examine the rules or facts, etc.


In Haskell type-level programming:
type  -> term
type constructor  -> function symbol
class name-> predicate symbol
class constraint  -> atomic formula (atomic goal)

There is a subset of Prolog called Datalog, which is commonly
defined as Prolog without function symbols.

Logic without function symbols is equivalent to logic with function
symbols, _provided_ we have the infinite supply of constants.
For example, Foo(f(x),g(x)) can be represented as
exists y y'. F(x,y) & G(x,y') & Foo(y,y')
So, each function symbol f of arity n is represented as a predicate
F of arity n+1. That predicate is a functional predicate: 
for each combination of the first n arguments, there exists exactly one
object (for the last argument) that makes the predicate hold.
Since terms in logic are finite, the infinitely countable supply
of constants is enough.

In Datalog however, the extensional database is finite. 
There is a finite number of facts and hence the finite number of
constants.  That breaks the above correspondence, and so terms like
f(f(f(... x))) can no longer be emulated as the corresponding F
predicate is finite (its domain is finite). That's why in pure
Datalog (without negation or with stratified negation), termination
is assured. This is not the case in pure Prolog because of the possibility
to construct longer and longer terms like succ(succ(x)).

Regarding termination, minimal models, and the correspondence between
logic formulas (and pure, positive, stratified, etc. Datalogs) and
P-complete etc. programs, please see

http://www.csupomona.edu/~jrfisher/www/logic_topics/positive/positive.html

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