RE: [Haskell-cafe] Haskell newbie indentation query.

2008-10-17 Thread Ramaswamy, Vivek
Thanks Jules and Daniel.

That was very helpful.

Regards
-Vivek Ramaswamy-


-Original Message-
From: Jules Bean [mailto:[EMAIL PROTECTED] 
Sent: 15 October 2008 18:19
To: Ramaswamy, Vivek
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Haskell newbie indentation query.

Ramaswamy, Vivek wrote:
 Hello All~
 
 I have just started with Haskell, and I must confess; I am in love
with it.
 
 However one area that I am really confused about is indentation.
 
 Lets take a look at if-else if- else block.

Important point 1.

There are two contexts in haskell programs. Layout and non-layout.

In a non-layout context you can do whatever you like with indentation. 
You can put the newlines wherever you want.

In practice, almost everyone uses layout for the 'top-level' of a 
module. That means that anything flush to the left margin starts a new 
declaration. However, making sure we are not flush to the left margin, 
the following are all fine


x = if True then 1 else 2
x = if True
  then 1
  else 2
x =
  if True
  then 1
  else 2

x =
if True
   then 1
  else 2

because, layout is not relevant in expressions.


Now, do blocks are layout blocks. So what you really want us to look 
at is the use of if/then/else in do blocks.

x =
  do
   if True
   then (return 1)
   else (return 2)

The first line in the do block defines the left margin for this block. 
In this example, the first line is the if line, that defines the left 
margin. Since the then and the else are also both on the left 
margin, they are new statements. So, the layout interprets as:

do {if True; then (return 1); else (return 2)}

...which is a parse error, because a statement cannot begin with 'then' 
or 'else'.

any pattern of indentation which keeps the if expression indented 
further to the right will be OK, such as

x =
  do
   if True
then (return 1)
 else (return 2)

x =
  do
   if True
 then (return 1)
else (return 2)

..are both fine.

Does that help?

Jules


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


Re: [Haskell-cafe] Re: What I wish someone had told me...

2008-10-17 Thread Paul Johnson

Derek Elkins wrote:

All you need is a T-shirt: http://www.cafepress.com/skicalc
  

Or http://www.cafepress.com/l_revolution

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


Re: [Haskell-cafe] Terminal-like Application Design

2008-10-17 Thread allan
Hi Jeff

It sounds like maybe you just want an application that works a bit like 'cabal'.
So with cabal the first argument is taken as the 'command' and then the rest 
are based on that:

cabal build --some other --options --which may --or --may --not have --arguments

Yi has a simple template for a script which should get you started, please find 
it attached.

So here instead of processOptions, you might want, processCommand

processCommand :: [ String ] - IO ()
processCommand (build : args) = processBuildCommand args
processCommand (play : args)  = processPlayCommand args
processCommand []   = putStrLn You must supply a command
processCommand _= putStrLn Sorry I don't understand your 
command --Probably out put help here as well

processBuildCommand :: [ String ] - IO ()
processBuildCommand = similar to the processOptions except now you are sure you 
are in a 'build' command

you *might* even have a separate set of option descreptions for each command.

hth
allan




Jeff Wheeler wrote:
 Hi,
 
 I'm a slight Haskell newbie, but I'm trying to write a terminal-like
 application that accepts simple commands with optional arguments, and
 can then execute them. Most of these commands will need IO, as later I
 will want to communicate over USB for most of them.
 
 I was hoping, though, that I could get some comments on the initial
 architecture I've been playing with [1].
 
 I suspect I should be using some sort of monad to represent the
 commands, but I don't fully understand monads, and am not sure how it
 would apply in this context.
 
 Should I be using a monad here, and if so, how?
 
 Thanks in advance,
 Jeff Wheeler
 
 [1] http://media.nokrev.com/junk/cli/
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 


-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

{-
-}
module Main
  ( main )
where

{- Standard Library Modules Imported -}
import System.Console.GetOpt
  ( getOpt
  , usageInfo
  , ArgOrder( .. )
  , OptDescr( .. )
  , ArgDescr( .. )
  )
import System.Environment
  ( getArgs
  , getProgName
  )
{- External Library Modules Imported -}
{- Local Modules Imported -}
{- End of Imports -}

data CliFlag =
CliHelp
  | CliVersion
  deriving Eq


options :: [ OptDescr CliFlag ]
options =
  [ Option   h [ help ]
(NoArg CliHelp)
Print the help message to standard out and then exit

  , Option   v [ version ]
(NoArg CliVersion)
Print out the version of this program
  ]

helpMessage :: String - String
helpMessage progName =
  usageInfo progName options

versionMessage :: String - String
versionMessage progName = 
  progName ++ : This is version 0.001

-- | The main exported function
main :: IO ()
main = getArgs = processOptions

processOptions :: [ String ] - IO ()
processOptions cliArgs =
  case getOpt Permute  options cliArgs of
(flags, args, [])   - 
  processArgs flags args
(_flags, _args, errors) - 
  do progName - getProgName
 ioError $ userError (concat errors ++ helpMessage progName)

-- We assume all of the arguments are files to process
processArgs :: [ CliFlag ] - [ String ] - IO ()
processArgs flags files
  | elem CliHelp flags= getProgName = (putStrLn . helpMessage)
  | elem CliVersion flags = getProgName = (putStrLn . versionMessage)
  | otherwise = mapM_ processFile files

-- Our processing of a file is to simply count the words
-- in the file and output the number as a line.
processFile :: FilePath - IO ()
processFile file =
  do contents - readFile file
 putStrLn (show $ length $ words contents)

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


Re: [Haskell-cafe] Re: Ubuntu Haskell

2008-10-17 Thread Magnus Therning
On Thu, Oct 16, 2008 at 8:12 PM, Duncan Coutts
[EMAIL PROTECTED] wrote:
 On Tue, 2008-10-14 at 11:25 +0100, Magnus Therning wrote:
 Playing the devil's advocate I'd say that cabal (not the library
 Cabal, but the tool cabal in cabal-install) is only needed on systems
 with pacakge managers that are broken or completely missing (e.g.
 Windows).  As such cabal is a waste of time and shouldn't have been
 written at all; on many systems it's of no use, on the ones where it
 is useful it's a fix at the wrong level.  Somewhat harsh, and not
 completely in line with my own opinion, but it can be argued that way.

 I think they're actually complementary. Sure on Windows it's needed in
 place of a native packaging system, but even on systems like debian it's
 still needed in places. It's needed for packages that are too new or are
 not sufficiently mature or popular to have been packaged yet for the
 distro. There will always be such packages. Of course many ordinary
 users would be able to make do with the subset of packages that are
 provided by the distro and that's great.

Yes, that would actually be my opinion as well, when my devil hat is off.

When putting it back on again though I'd say that the distro's own
package manager should be used also in this case, e.g. new versions of
stuff from Hackage should go into Debian experimental.

Taking the hat off again, cabal-install strikes me as a lighter
approach and more suited for bleeding-edge things.  On top of that
it's X-distro and X-platform.  All good things!

Enough of this schizophrenia.

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Terminal-like Application Design

2008-10-17 Thread Magnus Therning
2008/10/17 allan [EMAIL PROTECTED]:
 Hi Jeff

 It sounds like maybe you just want an application that works a bit like 
 'cabal'.
 So with cabal the first argument is taken as the 'command' and then the rest 
 are based on that:

 cabal build --some other --options --which may --or --may --not have 
 --arguments

 Yi has a simple template for a script which should get you started, please 
 find it attached.

 So here instead of processOptions, you might want, processCommand

 processCommand :: [ String ] - IO ()
 processCommand (build : args) = processBuildCommand args
 processCommand (play : args)  = processPlayCommand args
 processCommand []   = putStrLn You must supply a command
 processCommand _= putStrLn Sorry I don't understand your 
 command --Probably out put help here as well

 processBuildCommand :: [ String ] - IO ()
 processBuildCommand = similar to the processOptions except now you are sure 
 you are in a 'build' command

 you *might* even have a separate set of option descreptions for each command.

I wanted to throw in another idea, something I didn't come up with
myself but used in omnicodec[1].  Now I don't remember where I picked
up the idea:

1. Keep all option values as members of a type T
2. Define an instance of T with default values, dT
3. When using getOpt let the type of the options be something like
[OptDescr (T - IO T)]
4. To get the final set of values fold (=) over all the list of
arguments returned from getOpt and using dT as the start value.
Something like 'effectiveT - foldl (=) dT arguments'

In a tool I recently started working on I decided not to work in IO
and instead I ended up with something like 'effectiveT = (foldl (.) id
arguments) dT'.

/M

[1]: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/omnicodec

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [fun] HaskellDB Talk trailer

2008-10-17 Thread Bjorn Bringert
On Fri, Oct 17, 2008 at 1:54 AM, Don Stewart [EMAIL PROTECTED] wrote:
 kyagrd:
 There is an impressive HaskellDB Talk trailer on the web.

 http://www.vimeo.com/1983774

 Cheers to the HaskellDB developers :-)

 AWESOME!

 Trailers for talks, eh? The bar has been raised.

 -- Don

Sweet! There wouldn't happen to be a video or slides from the actual
talk? I couldn't find anything about it on the PDXPUG homepage.

Björn
A HaskellDB developer
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Invalid declaration names in TH that typecheck

2008-10-17 Thread Sean Leather
[I posted this on the Template Haskell list, but nobody seemed interested.
Thus, I'm re-posting it here for higher coverage.]

Apparently, I can create a function declaration (FunD) with a name
containing an invalid sequence of characters. It passes typechecking and
compiles. It even shows up in GHCi!

The function name is ep:#:, and the :#: is derived from an infix type
constructor. In GHCi (6.8.3), I type ep, hit Tab to get the list of
completions, and, sure enough, there it is! When I try to use it, GHCi
interprets it as two distinct symbols, ep and :#:, as it should.

Template Haskell's claim to fame is that it allows you to do type-safe
compile-time meta-programming, and while this issue is perhaps considered
lexical rather than type-level, I'm wondering if there should be some
additional error checking (somewhere) to account for this. I admit though,
that I wouldn't know how to do this easily within the bounds of the TH API.
The Name type is common to functions, infix operators, and everything else.
That which is valid for one is not necessarily so for the other.

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


[Haskell-cafe] howto mix - within do?

2008-10-17 Thread Larry Evans

The attached code produces error:
-- cut here --
runghc -dcore-lint do_with_assignment.proto.hs

do_with_assignment.proto.hs:30:2:
Couldn't match expected type `[]' against inferred type `IO'
  Expected type: [t]
  Inferred type: IO ()
In the expression: putStr v0=
In a 'do' expression: putStr v0=
-- cut here--

However, similar code here:

  http://www.nabble.com/List-as-input-p19987726.html

apparently does work.  Is there some compiler option I
need to use?  The compiler is ghc:

ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.2

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


[Haskell-cafe] OPPS, missing attachment (was Re: howto mix - within do?

2008-10-17 Thread Larry Evans

On 10/17/08 07:39, Larry Evans wrote:

The attached code produces error:
-- cut here --

[snip]

{- 
Purpose:
  Explore how to mix 'assignments' inside do.
Motivation:
  Instead of:
let 
  { v0 = e0
  ; v1 = e1 
  }
in do
  { print v0
  ; print v1
  }
  which is hard to read, recode above as:
do
  { v0 = e0
  ; print v0
  ; v1 = e1
  ; print v1
  }
  which is easier to read and more intuitive for
  c++ programmers.
Example_code_suggesting_should_work:
  http://www.nabble.com/List-as-input-p19987726.html
-}
module Main where
import Data.List
main = do
{ v0 - [999]
; putStr v0=
; print v0
}

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


Re: [Haskell-cafe] Terminal-like Application Design

2008-10-17 Thread Dougal Stanton
2008/10/17 Magnus Therning [EMAIL PROTECTED]:

 I wanted to throw in another idea, something I didn't come up with
 myself but used in omnicodec[1].  Now I don't remember where I picked
 up the idea:

This method is described in
http://www.haskell.org/haskellwiki/High-level_option_handling_with_GetOpt.

I have used it in the past and eventually end up with huge Config data
structures and not much separation of unrelated parts of the
computation. Of course, this is probably just me ;-)

Alternatively (and this is where I have had more success) you can take
several passes over the command arguments, using different parsers.
Each parser just ignores what it doesn't recognise:

parseArgs names = do
args - getArgs
let info = parseWith infoOptions []
let options = parseWith argOptions defaultOptArgs
let query = parseWith queryOptions defaultQuery
return (info, options, query)
 where parseWith os z = case getOpt Permute os args of
(o,_,_) - foldr id z o

Note that this method tends to ignore user error at the command line,
but I'm sure a hybrid could be constructed that was more chatty but
still quite clean at the back end.

See http://www.dougalstanton.net/code/buses/ for this code in its
wider context.

Cheers,


D

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


Re: [Haskell-cafe] OPPS, missing attachment (was Re: howto mix - within do?

2008-10-17 Thread Martijn van Steenbergen

Every statement in a do-expression has to be in the same monad.

You are mixing the list monad (v0 - [999]) with the IO monad (putStr 
v0=).


Instead of

v0 - [999]

try:

let v0 = [999]

Hope this helps,

Martijn.


Larry Evans wrote:

On 10/17/08 07:39, Larry Evans wrote:

The attached code produces error:
-- cut here --

[snip]




___
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] howto mix - within do?

2008-10-17 Thread Dougal Stanton
On Fri, Oct 17, 2008 at 1:39 PM, Larry Evans [EMAIL PROTECTED] wrote:
 do_with_assignment.proto.hs:30:2:
Couldn't match expected type `[]' against inferred type `IO'
  Expected type: [t]
  Inferred type: IO ()
In the expression: putStr v0=
In a 'do' expression: putStr v0=

Prelude let f = do { v - [999] ; return () }
Prelude :t f
f :: [()]
Prelude :t putStr 
putStr  :: IO ()


So v - [999] is in the list monad, but putStr is in the IO monad.
The two cannot mix in that way.

This looks like it might be homework so I'll refrain from saying any
more for now. Good luck!


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


Re: [Haskell-cafe] OPPS, missing attachment (was Re: howto mix - within do?

2008-10-17 Thread Daniel Fischer
Am Freitag, 17. Oktober 2008 14:42 schrieb Larry Evans:
 On 10/17/08 07:39, Larry Evans wrote:
  The attached code produces error:
  -- cut here --

 [snip]
 {- 
 Purpose:
   Explore how to mix 'assignments' inside do.
 Motivation:
   Instead of:
 let 
   { v0 = e0
   ; v1 = e1 
   }
 in do
   { print v0
   ; print v1
   }
   which is hard to read, recode above as:
 do
   { v0 = e0
   ; print v0
   ; v1 = e1
  ; print v1
   }

That would have to be
do let v0 = e0
   print v0
   let v1 = e1
   print v1

or
do v0 - return e0
   print v0
   v1 - return e1
   print v1

(better (?):
do print $ e0
   print $ e1
)
   which is easier to read and more intuitive for
   c++ programmers.

intuitive for c++ programmers is dangerous, the languages are very 
different, and one shouldn't gloss over that. The different syntax should 
help to not confound the languages.

 Example_code_suggesting_should_work:
   http://www.nabble.com/List-as-input-p19987726.html
 -}
 module Main where
 import Data.List
 main = do
 { v0 - [999]
 ; putStr v0=
 ; print v0
 }

remember that in

do value - action
   statements -- using value (or not)

action and statements must belong to the same monad. In your code above, the 
'action' [999] has type Num a = [a], so the monad is [], but putStr v0= 
has type IO (), the monad is IO. So the binding v0 - [999] and the statement 
putStr v0= can't appear in the same do-block.

If what you want is for every member of some list, do some monadic action, 
you need mapM/mapM_ resp forM(_):

mapM(_) (\v - putStr v0=  print v) [999]

or
forM(_) [999] $ (putStr v0= ) . print

especially

forM_ list $ \v - do
some
actions
with v

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


Re: [Haskell-cafe] List as input

2008-10-17 Thread leledumbo

So, what's the solution? This one:

(l::[Ord]) - readLn 

doesn't work (because Ord isn't a type constructor). It doesn't even comply
to Haskell 98 standard. I want to be able to read any list of ordered
elements.
-- 
View this message in context: 
http://www.nabble.com/List-as-input-tp19987726p20033244.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] List as input

2008-10-17 Thread Luke Palmer
On Fri, Oct 17, 2008 at 7:21 AM, leledumbo [EMAIL PROTECTED] wrote:

 So, what's the solution? This one:

 (l::[Ord]) - readLn

 doesn't work (because Ord isn't a type constructor). It doesn't even comply
 to Haskell 98 standard. I want to be able to read any list of ordered
 elements.

What you're after is not possible that easily.   What you want to do
is to read a bunch of elements, and based on what you read in,
determine their type.  This is contrary to static typing.

A number of ways are possible, but they all involve some sort of
enumeration of all the possible types to read in.

Way #1:  make a data type which represents any of the types of things
you can accept, and define Ordering on it.

  data Thing
= ThingInt Int
| ThingString String
| ThingList [Thing]
| ...
deriving Ord

And then define a parser to get from a string to a Thing (pretty easy
using ReadP or Parsec or something).

Note that this would accept a heterogeneous list like 1, foo, 2,
[3,bar,4], and it would sort it as 1, 2, foo, [3,bar,4], because
of the way Ord deriving works (all Ints are less than all Strings are
less than all Lists ...).  You can customize this by not using
deriving, and instead manually declaring the instance.

Way #2:  use the parser from way #1 to parse the first one and
determine what kind of thing you're reading, and then read a bunch of
those.

sortThings :: (Read a) = IO [a]

main = do
first - getLine
case first of
  ThingInt _ - print = (sortThings :: IO [Int])
  ThingString _ - print = (sortThings :: IO [String])
  ...

There are some other more clever ways.  But you will not be able to
get Haskell to make the choice for you.  In particular, there are some
ambiguous choices, for example is read 42 an Int, an Integer, a
Double ?   So you need to write an algorithm which resolves the
ambiguities.

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


Re: [Haskell-cafe] List as input

2008-10-17 Thread Dougal Stanton
On Fri, Oct 17, 2008 at 2:21 PM, leledumbo [EMAIL PROTECTED] wrote:

 So, what's the solution? This one:

 (l::[Ord]) - readLn

 doesn't work (because Ord isn't a type constructor). It doesn't even comply
 to Haskell 98 standard. I want to be able to read any list of ordered
 elements.

I hope to be enlightened, but I'm pretty sure this is not possible.
Your readLn has to present a list of some specific type which can be
inferred at compile time. Which type is it? String? Int? Something
else?

Also, neither Show nor Read relate to Ord, so you cannot ever be sure
that all Readable/Showable types are Ordered, or that all Ordered
types can be Read/Shown.


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


Re: [Haskell-cafe] List as input

2008-10-17 Thread Ryan Ingram
I can't think of a language that lets you do this; that is, allow you
to input a list of any type as text.

Some languages effectively encode the types in the parsing, for
example in LISP, you know that 'foo is a symbol.  It has a very
limited set of data types and new types are described entirely in
terms of those simple types, which makes parsing simple.  But lets say
you have

 data Color = Red | Green | Blue deriving (Read,Show,Eq,Ord)

Now you suddenly expect readLn to detect the word Green and
interpret it differently from 1.0, restricting the type at runtime?
Do you realize how difficult this is?

What if Green is also used in a type in another module?

You need to specify the type to read, or provide a parser that works
for every type you care about.

  -- ryan

On Fri, Oct 17, 2008 at 2:21 PM, leledumbo [EMAIL PROTECTED] wrote:

 So, what's the solution? This one:

 (l::[Ord]) - readLn

 doesn't work (because Ord isn't a type constructor). It doesn't even comply
 to Haskell 98 standard. I want to be able to read any list of ordered
 elements.
 --
 View this message in context: 
 http://www.nabble.com/List-as-input-tp19987726p20033244.html
 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.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


Re: [Haskell-cafe] List as input

2008-10-17 Thread David Leimbach
On Fri, Oct 17, 2008 at 6:21 AM, leledumbo [EMAIL PROTECTED]wrote:


 So, what's the solution? This one:

 (l::[Ord]) - readLn

 doesn't work (because Ord isn't a type constructor). It doesn't even comply
 to Haskell 98 standard. I want to be able to read any list of ordered
 elements.


The problem is one of decoding data from a data source.  This is usually
handled with parsers.  Neither static nor dynamic typing could really save
you here, unless the file is written out in a format that could be
automatically parsed by the input.  (like S-expressions perhaps for a lisp
read call...)
If it was as easy as your code would like it to be, people wouldn't have
bothered with things like XDR, XML, ASN.1 (BER) etc.  They'd just send
binary data everywhere.  How can you tell a 32bit value from four 8 bit
bytes for instance?

You must parse I think.



 --
 View this message in context:
 http://www.nabble.com/List-as-input-tp19987726p20033244.html
 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.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


[Haskell-cafe] Implementing pi-calculus using STM

2008-10-17 Thread Edsko de Vries

Hi,

(Note: assumes knowledge of pi-calculus.)

I am playing with writing a simple interpreter for the pi-calculus  
using STM. The implementation of most of the operators of the pi- 
calculus is straightforward, but I am unsure on how to implement the  
replication operator. The interpretation of !P should be the  
interpretation of the infinite number of parallel processes P | P |  
P ... . I am implementing parallel processes using the fork operation,  
but spawning an infinite amount of processes -- even if the (infinite)  
majority of them all immediately lock -- seems like a bad idea.


So I would prefer to spawn one P, and as soon as the thread that  
interprets P makes any progress at all, spawn another, and so on. I'm  
not too sure however how to achieve this.


Any ideas?

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


Re: [Haskell-cafe] Monadic Floating Point [was: Linking and unsafePerformIO]

2008-10-17 Thread Ariel J. Birnbaum
 It is an interesting question: can IEEE floating point be done purely
 while preserving the essential features. I've not looked very far so I
 don't know how far people have looked into this before.
Not sure. My doubts are mainly on interference between threads. If a thread 
can keep its FP state changes 'local' then maybe it could be done. I still 
think FP operations should be combined in a monad though --- after all, they 
depend on the evaluation order.

 Haskell currently only supports a subset of the IEEE FP api. One can
 assume that that's mainly because the native api for the extended
 features is imperative. But need it be so?

 Rounding modes sound to me like an implicit parameter. Traps and
 exception bits sound like the implementation mechanism of a couple
 standard exception handling strategies. The interesting thing here is
 that the exception handling strategy is actually an input parameter.
Reader? =)

 So part of the issue is a functional model of the FP api but the other
 part is what compiler support would be needed to make a functional api
 efficient. For example if the rounding mode is an implicit parameter to
 each operation like + - * etc then we need some mechanism to make sure
 that we don't have to actually set the FP rounding mode before each FP
 instruction, but only at points where we know it can change, like
 passing a new value for the implicit parameter, or calling into a thunk
 that uses FP instructions.
This one seems like a tough one to figure. Again, I'd vouch for a solution 
like STM --- composition of FP operations is allowed at a certain level 
(maybe enforcing some settings to remain constant here), while it takes a 
stronger level to connect them to their surroundings. 

 There's also the issue that if the Float/Double operations take an
 implicit parameter, can they actually be instances of Num? Is that
 allowed? I don't know.
Technically I guess they could, just like (Num a) = (b-a) can be made
an instance. It would look more like State though, IMO. Or Cont. Doesn't even 
look like Oleg-fu is needed.

Should they? That's a horse of a different colour. There are certain 
properties most programmers come to expect of such instances (regardless of 
whether the Report demands them or not), such as associativity of (+) and 
(==) being an equivalence that break miserably for floating point. 

Floating point is a hairy area for programing in general, but I think it's 
also one where Haskell can shine with an elegant, typesafe model.

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


[Haskell-cafe] Re: OPPS, missing attachment (was Re: howto mix - within do?

2008-10-17 Thread Larry Evans

On 10/17/08 08:12, Daniel Fischer wrote:

Thanks very much Daniel.


Am Freitag, 17. Oktober 2008 14:42 schrieb Larry Evans:

On 10/17/08 07:39, Larry Evans wrote:

The attached code produces error:
-- cut here --

[snip]
{- 
Purpose:

  Explore how to mix 'assignments' inside do.
Motivation:
  Instead of:
let 
  { v0 = e0
  ; v1 = e1 
  }

in do
  { print v0
  ; print v1
  }
  which is hard to read, recode above as:
do
  { v0 = e0
  ; print v0
  ; v1 = e1
 ; print v1
  }


That would have to be
do let v0 = e0
   print v0
   let v1 = e1
   print v1

or
do v0 - return e0
   print v0
   v1 - return e1
   print v1

(better (?):
do print $ e0
   print $ e1
)


At first, the |let v = e| combination looked best (less typing).
However, my actual e0 was more complicated:

  array_complete
  [ Expr   == Op0 GramOne
  , Term   == Op0 GramOne
  , Factor == Op0 GramOne
  ]

where == was a binary operator which just produced a tuple pair.
I wanted to keep the expression on multiple lines because it's
easier to read.  The == was defined to make the expression
look more like grammar productions (the Op0 GramOne is not
the final rhs.  That's only for testing purposes.).

Unfortunately, using let with the multiline rhs failed to
compile (due, I guess, to some layout rules, which I find
difficult to fathom).  So, I tried the | v - return e|
combination.  This worked although I had to surround e with
parenthesis to enable compilation with multiple lines:

  ; gram_eqs::GramEqs ArithInp ArithVar - return
  (array_complete
  [ Expr   == Op0 GramOne
  , Term   == Op0 GramOne
  , Factor == Op0 GramOne
  ])
  ; putStr gram_eqs=
  ; print gram_eqs

I didn't use the last combination |print $ e0|
because e1 may use v0.  IOW:

  v0 - return e0
  v1 - return ...v0...


  which is easier to read and more intuitive for
  c++ programmers.


intuitive for c++ programmers is dangerous, the languages are very 
different, and one shouldn't gloss over that. The different syntax should 
help to not confound the languages.


OK, but I'm finding it very difficult to figure out how to do
something that's very simple in c++:

  ; calculate e0
  ; store e0 in v0
  ; print v0
  ; calculate e1 using possibly v0
  ; store e1 in v1
  ; print v1

However, apparently, in haskell, the operands on each side of the ';'
must be compatible.  Hmmm, I remember seeing a translation of
more complex haskell statments/expression to simpler ones...
looking...

  http://haskell.org/onlinereport/exps.html#sect3.14

Mea culpa :(  I should have read that first.  Then
a would have realized:

  (v0 - e0)  putStr v0

would not have worked because, I guess:

  e0  putStr v0

would not work. OOPS, sect3.14 has a specialization on the pattern p-e.
That specialization is harder to understand.  I'll work on it :)

[snip]


remember that in

do value - action
   statements -- using value (or not)

action and statements must belong to the same monad. In your code above, the 
'action' [999] has type Num a = [a], so the monad is [], but putStr v0= 
has type IO (), the monad is IO. So the binding v0 - [999] and the statement 
putStr v0= can't appear in the same do-block.


If what you want is for every member of some list, do some monadic action, 
you need mapM/mapM_ resp forM(_):


Nope.  I just want to trace through various stages in translation of
a language grammar(a set of grammar equationss) to a corresponding
set of equations defining the lookahead sets for that grammar.
So, I want the do{...} to just be a sequence of (calculate value; print 
value} where calculate value may use previously calculated values).


Thanks for you help.

-regards,
Larry

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


Re: [Haskell-cafe] Invalid declaration names in TH that typecheck

2008-10-17 Thread Brandon S. Allbery KF8NH

On 2008 Oct 17, at 7:33, Sean Leather wrote:
Apparently, I can create a function declaration (FunD) with a name  
containing an invalid sequence of characters. It passes typechecking  
and compiles. It even shows up in GHCi!


This may be a feature.  Consider that internal functions use # as an  
alphanumeric (via an extension); it can be useful to have names that  
can't be used in ordinary code.


This is an inevitable aspect of being able to program at a level which  
permits symbol table manipulation.


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


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


Re: [Haskell-cafe] Re: OPPS, missing attachment (was Re: howto mix - within do?

2008-10-17 Thread Daniel Fischer
Am Freitag, 17. Oktober 2008 17:56 schrieb Larry Evans:
 On 10/17/08 08:12, Daniel Fischer wrote:

 At first, the |let v = e| combination looked best (less typing).
 However, my actual e0 was more complicated:

array_complete
[ Expr   == Op0 GramOne
, Term   == Op0 GramOne
, Factor == Op0 GramOne
]

 where == was a binary operator which just produced a tuple pair.
 I wanted to keep the expression on multiple lines because it's
 easier to read.  The == was defined to make the expression
 look more like grammar productions (the Op0 GramOne is not
 the final rhs.  That's only for testing purposes.).

 Unfortunately, using let with the multiline rhs failed to
 compile (due, I guess, to some layout rules, which I find
 difficult to fathom).

It would be no problem if you used only layout. The problem is that you used 
braces and semicolons for the do-block, but not for the let.
You would have to write it like

do { let { v0 = e0 }
   ; print v0
   }
, i.e. also use braces for the let block.
If you write
do { let v0 = e0
   ; print v0
   }
it would be parsed as

do { let { v0 = e0
 ; print v0
 }
   }

Either braces and semicolons everywhere or all layout, anything else invites 
misparsings.

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


[Haskell-cafe] Temlpate Haskell: [d| ... |]

2008-10-17 Thread Achim Schneider
 [d| ... |], where the ... is a list of top-level declarations; the
 quotation has type Q [Dec].

(http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html)

Can someone elaborate on what a list means here? Neither

declarations = [d| 
foo = bar
bar = foo 
|]

nor

declarations = [d| 
[ foo = bar
, bar = foo 
]
|]

work. I'm trying to automatically generate a bunch of functions out of
an xml file.

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

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


Re: [Haskell-cafe] Temlpate Haskell: [d| ... |]

2008-10-17 Thread Philip Weaver
On Fri, Oct 17, 2008 at 9:26 AM, Achim Schneider [EMAIL PROTECTED] wrote:

  [d| ... |], where the ... is a list of top-level declarations; the
  quotation has type Q [Dec].

 (
 http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html
 )

 Can someone elaborate on what a list means here? Neither

 declarations = [d|
foo = bar
bar = foo
 |]

 nor

 declarations = [d|
[ foo = bar
, bar = foo
]
 |]

 work. I'm trying to automatically generate a bunch of functions out of
 an xml file.


Works for me.  Note that -fth is needed.



 --
 (c) this sig last receiving data processing entity. Inspect headers
 for copyright history. All rights reserved. Copying, hiring, renting,
 performance and/or quoting of this signature prohibited.

 ___
 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] Re: What I wish someone had told

2008-10-17 Thread John Lato
Richard O'Keefe wrote:
 On 17 Oct 2008, at 9:53 am, Daryoush Mehrtash wrote:

 So does this mean that the reason for complexity of generics is the
 Java inheritance?

 No.  The reason for the complexity of generics in Java is that
 they weren't designed into the language in the first place.
 It took several attempts and quite a lot of work to come up with
 a version of generics that was 100% interoperable with earlier
 JVMs *and* still worth having.

 You could have something very like Java generics but without
 the strangeness if you designed it into the language from the
 beginning, as Betrand Meyer did with Eiffel.  Of course, what
 _he_ didn't design in from the beginning was lambdas, now
 present as agents.  Eiffel has its own kinds of strangeness.


Or C# generics, which are built into the IL (in .Net 2.0 and above).
In many ways, C# is a very nice language, and having generics fully
supported in reflection is pretty cool.  I do have some words to say
about various ASP.Net libraries, however...
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Temlpate Haskell: [d| ... |]

2008-10-17 Thread Achim Schneider
Philip Weaver [EMAIL PROTECTED] wrote:

 On Fri, Oct 17, 2008 at 9:26 AM, Achim Schneider [EMAIL PROTECTED]
 wrote:
 
   [d| ... |], where the ... is a list of top-level declarations;
   the quotation has type Q [Dec].
 
  (
  http://www.haskell.org/ghc/docs/latest/html/users_guide/template-haskell.html
  )
 
  Can someone elaborate on what a list means here? Neither
 
  declarations = [d|
 foo = bar
 bar = foo
  |]
 
  nor
 
  declarations = [d|
 [ foo = bar
 , bar = foo
 ]
  |]
 
  work. I'm trying to automatically generate a bunch of functions out
  of an xml file.
 
 
 Works for me.  Note that -fth is needed.
 
-fth doesn't make a difference here, I'm using -XTemplateHaskell with
ghc 6.8.3

Now if I wasn't sure that it somehow should work ([d| ... |]'s type is
Q [Dec], after all), I would write myself an concatM :: [m [a]] - m [a]


-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

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


[Haskell-cafe] Re: Pandoc questions

2008-10-17 Thread Andrew Coppin

John MacFarlane wrote:

+++ Andrew Coppin [Oct 12 08 11:21 ]:
  
There doesn't seem to be any option to make Pandoc produce actual MathML  
output. Is there a reason for this?



1. Nobody has written the LaTeX - MathML code yet, and I've been too
lazy.  Anyone who is interested in doing this should get in touch.
  


Well, I'd certainly be interested. I use mathematics *a lot* in my 
writing. Presumably modifying a large program like Pandoc is intractably 
difficult though?


It strikes me that perhaps using LaTeX to enter mathematical markup is 
rather against the spirit of Markdown. Surely there should be an option 
to include raw LaTeX, but a more natural encoding that covers most 
mathematics would be nice also. Of course, that means somebody has to 
design it first...



2. Not all browsers can process MathML. The current system (using the
LaTeXMathML.js javascript) has the advantage of falling back to raw
LaTeX in browsers that don't support MathML.
  


It's been a while since I looked, but I believe the spec provides a way 
to provide an alternative block of XML, similar to the 'alt' tag in 
the img element, for precisely this reason. (And if there was a math 
converter, rather than raw LaTeX you could provide something a little 
easier on the eyes given what raw Unicode + plain HTML can do...)


MathML has the advantage that it's machine-readable as well as 
human-readable. That probably doesn't matter right now, but maybe it 
will someday.


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


Re: [Haskell-cafe] Re: Temlpate Haskell: [d| ... |]

2008-10-17 Thread Robert Greayer
--- On Fri, 10/17/08, Achim Schneider [EMAIL PROTECTED] wrote:
   declarations = [d|
  foo = bar
  bar = foo
   |]
 -fth doesn't make a difference here, I'm using
 -XTemplateHaskell with
 ghc 6.8.3
 

The following lines, verbatim, pasted into a file, work for me with 6.8.3 with 
no command line options:

{-# LANGUAGE TemplateHaskell #-}
module TH where
import Language.Haskell.TH

declarations = [d|
   foo = bar
   bar = foo
   |]

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Temlpate Haskell: [d| ... |]

2008-10-17 Thread Achim Schneider
Robert Greayer [EMAIL PROTECTED] wrote:

 --- On Fri, 10/17/08, Achim Schneider [EMAIL PROTECTED] wrote:
declarations = [d|
   foo = bar
   bar = foo
|]
  -fth doesn't make a difference here, I'm using
  -XTemplateHaskell with
  ghc 6.8.3
  
 
 The following lines, verbatim, pasted into a file, work for me with
 6.8.3 with no command line options:
 
 {-# LANGUAGE TemplateHaskell #-}
 module TH where
 import Language.Haskell.TH
 
 declarations = [d|
foo = bar
bar = foo
|]
 
Argh. Yes. They do. While I certainly am in favour of layout rules, I'm
not in favour of one that gives raises an error if you don't indent the
closing |] by at least one whitespace.

declarations = 
[d| 
foo = bar
bar = foo 
|]

doesn't work, either, as 

declarations = 
[d| foo = bar
bar = foo 
|]

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.

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


[Haskell-cafe] Troubles getting isA of ArrowIf from HXT 8.10 to work as expected

2008-10-17 Thread Corey O'Connor
I'm attempting to use ifA to conditionalize generated XHTML.
ifA (arr test_status  arr (/= Running))
(mkelem a [attr href (arr test_log_URL 
mkText)] [txt log])
(mkelem a [attr href (arr test_log_URL 
mkText)] [txt no log])

The arrow type at the point of the ifA is (I think)  XmlArrow a = a
XmlTree TestRun where TestRun is defined as:
data TestRun = TestRun
{
test_log_URL:: String,
test_status :: String
}

The issue I'm seeing is that regardless of the predicate arrow the
result is always the same: The XmlTree for the True branch is always
generated. In other words, I get the same behavior using this code:
ifA (arr (const False))
(mkelem a [attr href (arr test_log_URL 
mkText)] [txt log])
(mkelem a [attr href (arr test_log_URL 
mkText)] [txt no log])

Which, I thought, the arr (const False) would force the ifA to
always descend the False path.

This is my first attempt at using HXT and Arrows (Which is otherwise
going great!) so I figure I'm missing something. Any ideas?

Cheers,
Corey O'Connor
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to deal with pointers to pointers in the FFI

2008-10-17 Thread Jefferson Heard
I have the following functions in C:

OGRErr  OGR_G_CreateFromWkb (unsigned char *, OGRSpatialReferenceH,
OGRGeometryH *, int)
OGRErr  OGR_G_CreateFromWkt (char **, OGRSpatialReferenceH, OGRGeometryH *)
voidOGR_G_DestroyGeometry (OGRGeometryH)
OGRGeometryHOGR_G_CreateGeometry (OGRwkbGeometryType)

The normal sequence of calls is

OGRGeometryH handle = OGR_G_CreateGeometry(SOME_TYPE);
// do stuff
OGR_G_DestroyGeometry(handle);

OR

OGR_G_CreateFromWkb(blob, ref, handle, 0);
// do stuff
OGR_G_DestroyGeometry(handle);

As you can see, in one case, I have to pass in a pointer to the
returned handle, and not just the handle.  How can I accomplish this
feat using a single type?

I had

data OGRGeometryH
type Geometry = Ptr OGRGeometryH

but then can I declare that a function returns a

Ptr (Geometry)

?



-- 
I try to take things like a crow; war and chaos don't always ruin a
picnic, they just mean you have to be careful what you swallow.

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


Re: [Haskell-cafe] How to deal with pointers to pointers in the FFI

2008-10-17 Thread Jake McArthur
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jefferson Heard wrote:
 I have the following functions in C:
 
 OGRErrOGR_G_CreateFromWkb (unsigned char *, OGRSpatialReferenceH,
 OGRGeometryH *, int)
 OGRErrOGR_G_CreateFromWkt (char **, OGRSpatialReferenceH, 
 OGRGeometryH *)
 void  OGR_G_DestroyGeometry (OGRGeometryH)
 OGRGeometryH  OGR_G_CreateGeometry (OGRwkbGeometryType)

Are these Ogre3D functions? If so, I hope you are planning on releasing
these bindings!

But I don't have an answer to your question, sorry. :\

- - Jake
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkj45dwACgkQye5hVyvIUKmRoQCfTOnlxfRCUY/9SY9qA29NNIJL
AvYAn1m6h8b36amu+DBqd/r1dT5iXb/H
=Smjr
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to deal with pointers to pointers in the FFI

2008-10-17 Thread Jefferson Heard
Sadly, nothing so awesome...  OGR is part of GDAL, an open-source
geographic information system suite.

On Fri, Oct 17, 2008 at 3:22 PM, Jake McArthur [EMAIL PROTECTED] wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Jefferson Heard wrote:
 I have the following functions in C:

 OGRErrOGR_G_CreateFromWkb (unsigned char *, OGRSpatialReferenceH,
 OGRGeometryH *, int)
 OGRErrOGR_G_CreateFromWkt (char **, OGRSpatialReferenceH, 
 OGRGeometryH *)
 void  OGR_G_DestroyGeometry (OGRGeometryH)
 OGRGeometryH  OGR_G_CreateGeometry (OGRwkbGeometryType)

 Are these Ogre3D functions? If so, I hope you are planning on releasing
 these bindings!

 But I don't have an answer to your question, sorry. :\

 - - Jake
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.9 (MingW32)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

 iEYEARECAAYFAkj45dwACgkQye5hVyvIUKmRoQCfTOnlxfRCUY/9SY9qA29NNIJL
 AvYAn1m6h8b36amu+DBqd/r1dT5iXb/H
 =Smjr
 -END PGP SIGNATURE-




-- 
I try to take things like a crow; war and chaos don't always ruin a
picnic, they just mean you have to be careful what you swallow.

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


Re: [Haskell-cafe] How to deal with pointers to pointers in the FFI

2008-10-17 Thread Jake McArthur
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jefferson Heard wrote:
 Sadly, nothing so awesome...  OGR is part of GDAL, an open-source
 geographic information system suite.
 
 On Fri, Oct 17, 2008 at 3:22 PM, Jake McArthur [EMAIL PROTECTED] wrote:
 Are these Ogre3D functions? If so, I hope you are planning on releasing
 these bindings!

Aw. As I understand it, there is no plain C interface to Ogre3D right
now, so I was wondering where these were coming from anyway. Oh well, I
can dream.


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkj46lIACgkQye5hVyvIUKlHGQCg0gE5QmoB51ZwGZ8i/dMgR1nJ
ny8An3HrwdoKQkS2jLoGf0KooFsOuaEz
=4kC8
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANNOUNCE: Glob 0.1, globbing library

2008-10-17 Thread Matti Niemenmaa
Greetings to all,

I hereby announce the release of Glob 0.1, a small library for glob-matching
purposes based on a subset of zsh's syntax.

Web page at: http://iki.fi/matti.niemenmaa/glob/index.html
Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Glob

Simple example: match (compile foo*baz) foobarbaz == True.

It can also group the contents of a directory given a list of patterns to match:
globDir [compile foo*baz] a directory containing foobarbaz and joe gives
([dir/foobarbaz],[dir/joe]).

Comments, complaints, feature requests, bug reports are all welcome. It should
work on both GHC 6.8 and 6.10, but I've only tested the latter.

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


[Haskell-cafe] Re: How to deal with pointers to pointers in the FFI

2008-10-17 Thread Ben Franksen
Jefferson Heard wrote:

 I have the following functions in C:
 
 OGRErrOGR_G_CreateFromWkb (unsigned char *, OGRSpatialReferenceH,
 OGRGeometryH *, int)
 OGRErrOGR_G_CreateFromWkt (char **, OGRSpatialReferenceH,
OGRGeometryH
 *)
 void  OGR_G_DestroyGeometry (OGRGeometryH)
 OGRGeometryH  OGR_G_CreateGeometry (OGRwkbGeometryType)
 
 The normal sequence of calls is
 
 OGRGeometryH handle = OGR_G_CreateGeometry(SOME_TYPE);
 // do stuff
 OGR_G_DestroyGeometry(handle);
 
 OR
 
 OGR_G_CreateFromWkb(blob, ref, handle, 0);
 // do stuff
 OGR_G_DestroyGeometry(handle);
 
 As you can see, in one case, I have to pass in a pointer to the
 returned handle, and not just the handle.  How can I accomplish this
 feat using a single type?
 
 I had
 
 data OGRGeometryH
 type Geometry = Ptr OGRGeometryH

Almost: Assuming that OGRGeometryH is some sort of pointer, e.g.

  typedef struct OGRGeometry *OGRGeometryH

you could write:

 data OGRGeometry
 type OGRGeometryH = Ptr OGRGeometry

where OGRGeometryH is the type that you API exports.

 foreign import ccall
   oGR_G_CreateFromWkb :: ...whatever... - Ptr OGRGeometryH - OGRErr

Note that  Ptr OGRGeometryH  is in fact a pointer to a pointer, just as the
C type demands. When calling such a procedure you must first allocate
space. This is most elegantly done using alloca (I have added some basic
error handling, otherwise the value returned might be undefined):

 createFromWbk :: ...argtypes... - Either OGRErr OGRGeometryH
 createFromWbk ...args... = alloca $ \ptr - do
   -- in this code block you can peek and poke the ptr;
   -- space will be deallocated after block exits
   res - oGR_G_CreateFromWkb ...args... ptr
   if checkResultOK res
 then do
   -- this can be shortened to: liftM Right $ peek ptr
   -- or: peek ptr = return . Right
   h - peek ptr
   return (Right h)
 else return (Left res)

(Instead of returning an Either type you could throw exceptions, but you
didn't ask about error handling, did you ?-)

Cheers
Ben

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


[Haskell-cafe] Re: Compiling regex-posix-0.93.2 on windows

2008-10-17 Thread Chris Kuklewicz
I am not sure what is going wrong.  I have not been using Haskell on windows.  I 
am also copying this reply to haskell-cafe and libaries mailing lists.  Does 
anyone know?


Parnell Flynn wrote:
I am having a terrible time compiling the 0.93.2 version of the 
regex-posix library on windows XP.


I have Cygwin and MinGW installed and I have a version of the regex.h 
header in C:/cygwin/usr/include what shared libraries do I need?


Here is a copy of the error it finds the include but is unable to link.

This links to the standard c library version of regular expressions.

The corresponding c header file is regex.h and there is a chance you

will need to edit the end of the regex-posix.cabal file to find the

include directory and/or library.

Preprocessing library regex-posix-0.93.2...

dist/build/Text/Regex/Posix/Wrap_hsc_make.o(.text+0x85):Wrap_hsc_make.c: 
undefined reference to `_impure_ptr'


dist/build/Text/Regex/Posix/Wrap_hsc_make.o(.text+0xc9):Wrap_hsc_make.c: 
undefined reference to `_impure_ptr'


dist/build/Text/Regex/Posix/Wrap_hsc_make.o(.text+0xf1):Wrap_hsc_make.c: 
undefined reference to `_impure_ptr'


dist/build/Text/Regex/Posix/Wrap_hsc_make.o(.text+0x125):Wrap_hsc_make.c: 
undefined reference to `_impure_ptr'


dist/build/Text/Regex/Posix/Wrap_hsc_make.o(.text+0x159):Wrap_hsc_make.c: 
undefined reference to `_impure_ptr'


dist/build/Text/Regex/Posix/Wrap_hsc_make.o(.text+0x18d):Wrap_hsc_make.c: 
more undefined references to `_impure_ptr' follow


collect2: ld returned 1 exit status

linking dist\build\Text\Regex\Posix\Wrap_hsc_make.o failed

command was: y:\ghc\ghc-6.8.2\bin\ghc.exe -optl-LC:/cygwin/lib 
dist\build\Text\Regex\Posix\Wrap_hsc_make.o -o 
dist\build\Text\Regex\Posix\Wrap_hsc_make.exe


bash-3.2$

Thanks,

Parnell

Parnell Flynn • 230 South Lasalle Street • Suite 400 • Chicago, IL 60604 
• 312.244.5317 (o) •  [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED]




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


[Haskell-cafe] Fwd: [Haskell-beginners] HaXml.SAX successfully parses a malformed XML document

2008-10-17 Thread David Frey
I asked this question on the haskell-beginners list, but I didn't get a
response, so I am forwarding it on to the cafe list.

David


--- Original Message ---
Date: 10/16/2008
From: David Frey [EMAIL PROTECTED]
Subject: [Haskell-beginners] HaXml.SAX successfully parses a malformed
XML document


It seems that saxParse from Text.XML.HaXml.SAX will successfully parse a
malformed XML document.

Notice that the SubElem opening and closing tag are not matched in the
XML document below.

--- input.xml ---
RootNode
ElemOne
SubElem attr=fooelement data/SubElemBroken
NoDataElem/
ElemOne
/RootNode
--- end input.xml ---


The Haskell code below runs without error.  It prints out the type of
elements found during the parse.


--- Haskell Code ---
module Main where

import qualified Text.XML.HaXml.SAX as SAX
import Data.Maybe

main = let inputFilename = input.xml in
do content - readFile inputFilename
   let (elements, error) = SAX.saxParse inputFilename content
   if isNothing error
then mapM_ putStrLn (summarizeElements elements)
else putStrLn $ ERROR: ++ (fromJust error)



summarizeElements :: [SAX.SaxElement] - [String]
summarizeElements elements = map summarizeElement elements


summarizeElement :: SAX.SaxElement - String
summarizeElement element = case element of
(SAX.SaxDocTypeDecl d)   - DocType
(SAX.SaxProcessingInstruction p) - Processing Instruction
(SAX.SaxComment s)   - Comment
(SAX.SaxElementOpen name attrs)  - Element Open
(SAX.SaxElementClose name)   - Element Close
(SAX.SaxElementTag name attrs)   - No Content Element
(SAX.SaxCharData charData)   - Character Data
(SAX.SaxReference reference) - Reference

--- End Haskell Code ---


The Python code below throws an exception when parsing the same input
document.


--- Python Code ---
from xml.sax import make_parser
from xml.sax.handler import ContentHandler


def main():
c = ContentHandler()
p = make_parser()
p.setContentHandler(c)
p.parse(open('input.xml'))


if __name__ == '__main__':
main()
-- End Python Code ---


Is this a bug in the HaXml SAX parser?

Thanks,
David
___
Beginners mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/beginners
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Glut using freeglut and non starndard header / lib location?

2008-10-17 Thread Marc Weber
Which is the way to install the glut library with non standard header /
lib location?

I've tried setting CFLAGS before running 
./configure
./setup configure

and adding the include directory this way
  include-dirs: include, 
/nix/store/rz4nfm5qcrjrk0jsr1lxnjwamgxmgip8-freeglut-2.4.0/include

All results in
checking for GL/glut.h... (cached) no
checking GLUT/glut.h usability... no
checking GLUT/glut.h presence... no
checking for GLUT/glut.h... no
configure: error: no GLUT header found, so this package cannot be built

The configure script is meant to be run by cabal only?

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


[Haskell-cafe] package question/problem

2008-10-17 Thread Galchin, Vasili
Hello,

I am trying to cabal install HSQL. I am using ghc 6.8.2. I get the
following error about a non-visible/hidden package (old-time-1.0.0.0):

[EMAIL PROTECTED]:~$ cabal install hsql
Resolving dependencies...
'hsql-1.7' is cached.
[1 of 1] Compiling Main ( Setup.lhs, dist/setup/Main.o )
Linking dist/setup/setup ...
Configuring hsql-1.7...
Warning: No 'build-type' specified. If you do not need a custom Setup.hs or
./configure script then use 'build-type: Simple'.
Preprocessing library hsql-1.7...
Building hsql-1.7...

Database/HSQL.hsc:66:7:
Could not find module `System.Time':
  it is a member of package old-time-1.0.0.0, which is hidden
cabal: Error: some packages failed to install:
hsql-1.7 failed during the building phase. The exception was:
exit: ExitFailure 1
[EMAIL PROTECTED]:~$

I don't see (old-time-1.0.0.0) with parens around it so I am confused:

[EMAIL PROTECTED]:~$ ghc-pkg list
/usr/local/lib/ghc-6.8.2/package.conf:
Cabal-1.2.3.0, GLUT-2.1.1.1, HUnit-1.2.0.0, OpenGL-2.2.1.1,
QuickCheck-1.1.0.0, array-0.1.0.0, base-3.0.1.0,
bytestring-0.9.0.1, cgi-3001.1.5.1, containers-0.1.0.1,
directory-1.0.0.0, fgl-5.4.1.1, filepath-1.1.0.0, (ghc-6.8.2),
haskell-src-1.0.1.1, haskell98-1.0.1.0, hpc-0.5.0.0, html-1.0.1.1,
mtl-1.1.0.0, network-2.1.0.0, old-locale-1.0.0.0, old-time-1.0.0.0,
packedstring-0.1.0.0, parallel-1.0.0.0, parsec-2.1.0.0,
pretty-1.0.0.0, process-1.0.0.0, random-1.0.0.0, readline-1.0.1.0,
regex-base-0.72.0.1, regex-compat-0.71.0.1, regex-posix-0.72.0.2,
rts-1.0, stm-2.1.1.0, template-haskell-2.2.0.0, time-1.1.2.0,
unix-2.3.0.0, xhtml-3000.0.2.1
/home/vigalchin/.ghc/i386-linux-6.8.2/package.conf:
Cabal-1.4.0.1, GLFW-0.3, HDBC-1.1.5, HTTP-3001.0.4,
MonadRandom-0.1.1, Stream-0.2.6, Takusen-0.8.3, X11-1.4.2,
arrows-0.4, binary-0.4.2, category-extras-0.53.5, chp-1.1.0,
dlist-0.4.1, event-list-0.0.7, ipc-0.0.3, midi-0.0.6, mtl-1.1.0.1,
network-bytestring-0.1.1.2, non-negative-0.0.3,
posix-realtime-0.0.0.1, posix-realtime-0.0.0.2, probability-0.2.1,
quantum-arrow-0.0.4, unix-2.4.0.0, zlib-0.4.0.4

??

What is the history of old-time package?

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


[Haskell-cafe] mysql server on Linux

2008-10-17 Thread Galchin, Vasili
Hello,

 I want to use the mysql server (mysqld) on Linux. What Haskell packages
must I install in order to write a Haskell mysql package??

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


Re: [Haskell-cafe] package question/problem

2008-10-17 Thread Marc Weber
Hi Vasili,

have a look at all options of ghc-pkg. There is one command to hide a
package. Hidden packages will be shown by ghc-pkg list in parenthesis.
The second way to hide packages is passing a special option to ghc (you
can look it up in the ghc documentation or by running ./setup build
-v3). Probably here it's another reason: Maybe the build-depends fields
of the package are wrong. So just open the .cabal file and add it.
pay attention to
if flag(...)
  build-depends :
else
  build-depends :
so that you add it to the right one.

What is the history of old-time package?
Hmm. It's superseded by the new time library found on hackage..
I hope that this message will help you.

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


Re: [Haskell-cafe] mysql server on Linux

2008-10-17 Thread Marc Weber
On Fri, Oct 17, 2008 at 06:27:43PM -0500, Galchin, Vasili wrote:
Hello,
 I want to use the mysql server (mysqld) on Linux. What Haskell
packages must I install in order to write a Haskell mysql package??

What do you mean by mysql package?
Do you want to write either an application or an library connecting to
the mysqld-server executing some queries?

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


[Haskell-cafe] Re: Pandoc questions

2008-10-17 Thread John MacFarlane
 1. Nobody has written the LaTeX - MathML code yet, and I've been too
 lazy.  Anyone who is interested in doing this should get in touch.
   

 Well, I'd certainly be interested. I use mathematics *a lot* in my  
 writing. Presumably modifying a large program like Pandoc is intractably  
 difficult though?

Just write a separate library that parses LaTeX input and returns MathML
output. Pandoc could then use this library. So you wouldn't need to know
anything about pandoc's internals. Just write a function 

teXMathToMathML :: String - String. 

This would be a great contribution!  You could get a head start by
looking at the LaTeXMathML.js code.

 It strikes me that perhaps using LaTeX to enter mathematical markup is  
 rather against the spirit of Markdown. Surely there should be an option  
 to include raw LaTeX, but a more natural encoding that covers most  
 mathematics would be nice also. Of course, that means somebody has to  
 design it first...

I think it makes good sense to use LaTeX, which is already designed to
be natural but flexible, and is already known by most mathematicians.
My guess is that in designing a more natural format, one would
eventually reinvent something like LaTeX...

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


Re: [Haskell-cafe] Implementing pi-calculus using STM

2008-10-17 Thread Derek Elkins
On Fri, 2008-10-17 at 14:56 +0100, Edsko de Vries wrote:
 Hi,
 
 (Note: assumes knowledge of pi-calculus.)
 
 I am playing with writing a simple interpreter for the pi-calculus  
 using STM. The implementation of most of the operators of the pi- 
 calculus is straightforward, but I am unsure on how to implement the  
 replication operator. The interpretation of !P should be the  
 interpretation of the infinite number of parallel processes P | P |  
 P ... . I am implementing parallel processes using the fork operation,  
 but spawning an infinite amount of processes -- even if the (infinite)  
 majority of them all immediately lock -- seems like a bad idea.
 
 So I would prefer to spawn one P, and as soon as the thread that  
 interprets P makes any progress at all, spawn another, and so on. I'm  
 not too sure however how to achieve this.

Typically replication is restricted to replicated input for reasons akin
to this.

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