Re: [Haskell-cafe] Relaxing atomicity of STM transactions

2010-09-29 Thread Sterling Clover
Clojure has a commute operator whose semantics seem appropriate to your 
concerns:

http://clojure.org/refs
http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/commute

Commute in haskell would be roughly :: TVar a - (a - a) - STM a.
The TVar touched by commute does not get marked such that the transaction could 
retry. Nor is the TVar itself even updated at the time. Rather, it is read, and 
the result of applying some transform to it is returned. Then, when the 
transaction commits, the tvar is atomically modified by the function and 
actually updated. This works if the operation commutes with all other 
operations performed on the TVar anywhere else that may be running 
concurrently, and if no essential use (i.e. requiring atomicity) is made of the 
value returned from commute. Both properties can only be enforced by the 
discipline of the programmer.

I don't know how much discussion there's been in the Clojure community about 
the utility of commute, as a quick google mainly reveals people trying to 
either figure it out or explain it.

Cheers,
Sterl.

On Sep 28, 2010, at 7:36 PM, Tom Hawkins wrote:

 Thanks for the responses, but I think I should explain a bit more.
 I'm not interested in being able to read the live value of a TVar at
 any arbitrary time (via. unsafeIOToSTM).  But rather I would like
 looslyReadTVar to have exactly the same semantics as readTVar, except
 that the STM runtime would not reject the transaction if the TVar is
 modified by another transaction before the atomic commit takes place.
 
 Also, as I would be implementing something similar in Atom, I'm not
 necessarily interested in a Haskell implementation, but rather if the
 programming experience is elevated by these alternative semantics.
 
 For example:
 
 incr :: TVar - STM ()
 incr a = looslyReadTVar a = writeTVar a . (+ 1)
 
 decr a :: TVar - STM ()
 decr a = readTVar a = writeTVar a . (- 1)
 
 If incr and decr where atomically started at the same time with the
 same TVar, decr would be rejected if incr completed first, but not the
 other way around.  The initial reaction may be that this seriously
 breaks the atomicity of STM, but there may be cases where this could
 be useful.  For instance, it allow a computationally expensive
 transactions to complete, even if their inputs are constantly being
 modified.  In the embedded domain, this could be a fault monitor that
 reads a bunch of constantly changing sensors.
 
 -Tom
 ___
 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] Retargeting Haskell compiler to embedded/hardware

2010-09-29 Thread Vo Minh Thu
2010/9/29 Tom Hawkins tomahawk...@gmail.com:
 On Tue, Sep 28, 2010 at 9:20 PM, Shakthi Kannan shakthim...@gmail.com wrote:
 If you are still at it, you can have a look at Chalmers Lava [1], or
 Kansas Lava [2].
 Feldspar [3] project targets DSP though.

 These are examples light embedded DSLs, i.e. sophisticated libraries
 where you compile, then run the program to generate code.  This is not
 what I want.  Rather, I am looking for advice on how to splice GHC --
 or another implementation -- where I can build a compiler starting
 from a type checked, simplified Haskell AST; or better yet, an
 unevaluated call graph.

Hi Tom,

How much of GHC's Haskell do you want? If you are happy with something
*similar* to Haskell, did you consider to implement (or reuse if
something exists) your own concrete syntax and type checker? I would
think those problems are quite lightweight in regard to writing a new
backend.

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


[Haskell-cafe] Re: Parsec question (new user): unexpected end of input

2010-09-29 Thread Christian Maeder
Am 29.09.2010 05:35, schrieb Peter Schmitz:
[...]
 Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1):
 unexpected end of input
 expecting 
 
 The input was:
[...]
 
 -- Parsers:
 taggedContent = do
optionalWhiteSpace
aTag
many tagOrContent
aTag

many tagOrContent will consume all tags, so that no tag for the
following aTag will be left.

Cheers Christian

eof
return Parse complete.

 tagOrContent = aTag | someContent ? tagOrContent

 aTag = do
tagBegin
xs - many (noneOf [tagEndChar])
tagEnd
optionalWhiteSpace
return ()

 someContent = do
manyTill anyChar tagBegin
return ()

 optionalWhiteSpace = spaces   -- i.e., any of  \v\f\t\r\n
 tagBegin = char tagBeginChar
 tagEnd = char tagEndChar

 -- Etc:
 tagBeginChar = ''
 tagEndChar = ''
 
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Retargeting Haskell compiler to embedded/hardware

2010-09-29 Thread Sean Leather
Don Stewart:

 tomahawkins:
  A few years ago I attempted to build a Haskell hardware compiler
  (Haskell - Verilog) based on the Yhc frontent.  At the time I was
  trying to overcome several problems [1] with implementing a hardware
  description language as a light eDSL, which convinced me a proper
  compiler may be a better approach.  Yhc was recommended as a good
  starting point since it had a simpler IR compared with GHC -- at least
  at the time.
 
  I am considering restarting this effort, but this time to target hard
  realtime embedded code.  What is the recommended compiler to start
  from?  I need an IR that is post type checking with as much desugaring
  as possible, and a code base that is relatively easy to splice and
  build.
 
  My other requirement is not to be bound to IO () for 'main'.  The top
  level will be a monad, but with different semantics than IO.  I would
  also like to reuse the standard library, with exception to the values
  related to IO.
 
  What are my options?

 Have you looked at Clash, the GHC to VHDL compiler?


Links are always useful:

  http://clash.ewi.utwente.nl/
  http://hackage.haskell.org/package/clash
  http://dutchhug.nl/static/dutchhugday-2010/clash.pdf
  http://wiki.clean.cs.ru.nl/images/8/86/Christiaan-from-haskell-to.pdf

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


Re: [Haskell-cafe] Relaxing atomicity of STM transactions

2010-09-29 Thread Arie Middelkoop
Hi Tom,

You wrote that you are interested in the programming experience with relaxed 
atomicity. What you are asking for are the ideas behind Twilight STM, written 
in these papers:

 http://proglang.informatik.uni-freiburg.de/projects/syncstm/techreport2010twilight.pdf
(brief summary of the underlying ideas + rationale. Newer version available 
upon request)

 http://www.cs.uu.nl/research/techreps/repo/CS-2010/2010-020.pdf
(about a nicer API for Twilight using Haskell + formalization. Search in the 
document for twilight)

For experimental purposes, we have implementations in C, Java and Haskell. 
Annette already replied to this thread with a link to our Haskell 
implementation. 

The main idea is to change (only) the commit protocol of a transaction. The 
transaction (speculatively/lockless) executes as always: depending on its 
semantics, it may restart when it reads a value that has been modified since 
the start of a transaction, or if you use a multi-versioning STM, perhaps read 
data from older memory snapshots. What semantics you choose here is of no real 
concern as long as the transaction reaches its commit-point while having read 
data from a consistent memory snapshot. At the commit-point, however, we do 
something special: the programmer can provide code to manually validate the 
transaction using a special API.

At the commit point, we first put the transaction in an irrevocable state. This 
ensures that at any point the programmer's validation code gives an OK, we can 
publish the outcome of the transaction. We then validate the transaction 
(without restarting) to discover inconsistencies. Finally, the validation code 
is executed to inspect these inconsistencies.

To easily inspect these inconsistencies, you can tag all reads in the 
transactional body with region identifiers. In the validation code, you can 
then query if this region has become inconsistent, and what the new values are. 
These new values are again taken from a consistent memory snapshot - important!
In the example that you provided, this would mean that the reference that you 
want to loosely read from, you tag with a special region. In the validation 
code, you can then easily ignore its inconsistency. Or, more likely: inspect 
the new value to see if the difference with the actual read value is not too 
big.

Additionally, in the validation code, since the transaction is irrevocable, it 
is possible to safely do I/O, and you can change the outcome of the transaction 
slightly based on the new values inspected, i.e. repair the inconsistencies. 
These ideas provide a more fundamental way to deal with relaxed atomicity, 
whereas just reading loosely from a variable is not. In the latter case, you 
have no clue how out-dated the values are that you read, for example. 

Hope this is useful to you,
Arie

 Thanks for the responses, but I think I should explain a bit more.
 I'm not interested in being able to read the live value of a TVar at
 any arbitrary time (via. unsafeIOToSTM).  But rather I would like
 looslyReadTVar to have exactly the same semantics as readTVar, except
 that the STM runtime would not reject the transaction if the TVar is
 modified by another transaction before the atomic commit takes place.
 
 Also, as I would be implementing something similar in Atom, I'm not
 necessarily interested in a Haskell implementation, but rather if the
 programming experience is elevated by these alternative semantics.
 
 For example:
 
 incr :: TVar - STM ()
 incr a = looslyReadTVar a = writeTVar a . (+ 1)
 
 decr a :: TVar - STM ()
 decr a = readTVar a = writeTVar a . (- 1)
 
 If incr and decr where atomically started at the same time with the
 same TVar, decr would be rejected if incr completed first, but not the
 other way around.  The initial reaction may be that this seriously
 breaks the atomicity of STM, but there may be cases where this could
 be useful.  For instance, it allow a computationally expensive
 transactions to complete, even if their inputs are constantly being
 modified.  In the embedded domain, this could be a fault monitor that
 reads a bunch of constantly changing sensors.

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


Re: [Haskell-cafe] Inverse of HaskellDB

2010-09-29 Thread Chris Eidhof
On 28 sep 2010, at 17:33, Ozgur Akgun wrote:

 How do you define relationships between data types?
 
 Well, why is it any different from other fields? From one of your examples 
 [1], I'd expect you to have a list of questions in the Quiz data type, and if 
 necessary, a quiz field in the Question data type. This might be a bit tricky 
 but certainly achievable [2].

This is really tricky. For example, consider storing a large tree in the 
database:

 data Tree = Node Int Tree Tree | Leaf Int

This means you need to read the entire tree from the database. Or consider 
cyclic datastructures (such as the example you gave). How do you store this? 
The only way to inspect this is using a library like data-reify [1].

I think the problem might be a bit harder than you suspect.

Another way to solve it is using Sebastiaan Visser's framework, described in 
his paper [2], but that's also rather complicated.

-chris

[1]: http://hackage.haskell.org/package/data-reify
[2]: 
http://github.com/downloads/sebastiaanvisser/msc-thesis/wgp10-genstorage.pdf___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Re[Haskell-cafe] targeting Haskell compiler to embedded/hardware

2010-09-29 Thread -Steffen

If you are really interested in embedded realtime code you may want to have a
look at the timber language[1] or bit-c[2]. Another very interesting project
is this[3] developing a new Haskell like language called Habit for systems
programming.

There are also some great papers about systems programming and problems in
Haskell. For example Strongly typed memory areas programming systems-level
data structures in a functional language.

[1] http://www.timber-lang.org/
[2] http://www.bitc-lang.org/
[3] http://hasp.cs.pdx.edu/
[4] http://web.cecs.pdx.edu/~mpj/pubs/bytedata.pdf




Tom Hawkins-2 wrote:
 
 A few years ago I attempted to build a Haskell hardware compiler
 (Haskell - Verilog) based on the Yhc frontent.  At the time I was
 trying to overcome several problems [1] with implementing a hardware
 description language as a light eDSL, which convinced me a proper
 compiler may be a better approach.  Yhc was recommended as a good
 starting point since it had a simpler IR compared with GHC -- at least
 at the time.
 
 I am considering restarting this effort, but this time to target hard
 realtime embedded code.  What is the recommended compiler to start
 from?  I need an IR that is post type checking with as much desugaring
 as possible, and a code base that is relatively easy to splice and
 build.
 
 My other requirement is not to be bound to IO () for 'main'.  The top
 level will be a monad, but with different semantics than IO.  I would
 also like to reuse the standard library, with exception to the values
 related to IO.
 
 What are my options?
 
 Thanks.
 
 -Tom
 
 [1] Lack of observable sharing; function definitions, case
 expressions, ADTs disappear at compile time; etc.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 

-- 
View this message in context: 
http://old.nabble.com/Retargeting-Haskell-compiler-to-embedded-hardware-tp29834645p29836816.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] Re: Parsec question (new user): unexpected end of input

2010-09-29 Thread Christian Maeder
Am 29.09.2010 09:54, schrieb Christian Maeder:
 Am 29.09.2010 05:35, schrieb Peter Schmitz:
 [...]
 Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1):
 unexpected end of input
 expecting 

 The input was:
 [...]

 -- Parsers:
 taggedContent = do
optionalWhiteSpace
aTag
many tagOrContent
aTag
 
 many tagOrContent will consume all tags, so that no tag for the
 following aTag will be left.

if you want to match a final tag, you could try:

  manyTill tagOrContent (try (aTag  eof))

 
 Cheers Christian
 
eof
return Parse complete.

 tagOrContent = aTag | someContent ? tagOrContent

 aTag = do
tagBegin
xs - many (noneOf [tagEndChar])

this also looks like manyTill anyChar tagEnd

C.

tagEnd
optionalWhiteSpace
return ()

 someContent = do
manyTill anyChar tagBegin
return ()

 optionalWhiteSpace = spaces   -- i.e., any of  \v\f\t\r\n
 tagBegin = char tagBeginChar
 tagEnd = char tagEndChar

 -- Etc:
 tagBeginChar = ''
 tagEndChar = ''

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


Re: [Haskell-cafe] Inverse of HaskellDB

2010-09-29 Thread Ozgur Akgun
OK, I am rephrasing it a bit then :)
I definitely don't think this would be trivial to implement. However, I'd
expect a decent solution to this problem, not to have special combinators to
describe relations between data types, but let the user model their data
using plain haskell data types, and infer the associated table structure
just by looking at the data types.

I'll give this a harder thought once I find the time. There is the huge
barrier of TH, stopping me from playing with things like this.

Anyway, have fun! :)

On 29 September 2010 10:41, Chris Eidhof ch...@eidhof.nl wrote:

 On 28 sep 2010, at 17:33, Ozgur Akgun wrote:

  How do you define relationships between data types?
 
  Well, why is it any different from other fields? From one of your
 examples [1], I'd expect you to have a list of questions in the Quiz data
 type, and if necessary, a quiz field in the Question data type. This might
 be a bit tricky but certainly achievable [2].

 This is really tricky. For example, consider storing a large tree in the
 database:

  data Tree = Node Int Tree Tree | Leaf Int

 This means you need to read the entire tree from the database. Or consider
 cyclic datastructures (such as the example you gave). How do you store this?
 The only way to inspect this is using a library like data-reify [1].

 I think the problem might be a bit harder than you suspect.

 Another way to solve it is using Sebastiaan Visser's framework, described
 in his paper [2], but that's also rather complicated.

 -chris

 [1]: http://hackage.haskell.org/package/data-reify
 [2]:
 http://github.com/downloads/sebastiaanvisser/msc-thesis/wgp10-genstorage.pdf




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


Re: [Haskell-cafe] Inverse of HaskellDB

2010-09-29 Thread Michael Snoyman
I think this approach is not possible without involving some fairly
ugly unsafeInterleaveIO/unsafePerformIO calls. A simple example using
a common web programming example: support I have a multi-user blog
site, where each user can have multiple entries. I would model this
using standard Haskell datatypes as:

data Entry = Entry { title :: String, content :: String }
data Blogger = Blogger { name :: String, entries :: [Entry] }

Obviously we'll need some kind of blogger loading function:

getBloggerByName :: String - IO Blogger

Either this will load up all entries (a potentially incredibly costly
operation) or use unsafe IO down the road. Especially when using
database connections, this can be incredibly bad: the connection could
be closed, the SQL statement could be reused by another request, etc.

My persistent library follows a similar approach to what Chris
describes, though with a very different syntax. You can see a very
similar example on the documentation site[1].

Michael

[1] http://docs.yesodweb.com/book/persistent/#relations

On Wed, Sep 29, 2010 at 12:01 PM, Ozgur Akgun ozgurak...@gmail.com wrote:
 OK, I am rephrasing it a bit then :)
 I definitely don't think this would be trivial to implement. However, I'd
 expect a decent solution to this problem, not to have special combinators to
 describe relations between data types, but let the user model their data
 using plain haskell data types, and infer the associated table structure
 just by looking at the data types.
 I'll give this a harder thought once I find the time. There is the huge
 barrier of TH, stopping me from playing with things like this.
 Anyway, have fun! :)

 On 29 September 2010 10:41, Chris Eidhof ch...@eidhof.nl wrote:

 On 28 sep 2010, at 17:33, Ozgur Akgun wrote:

  How do you define relationships between data types?
 
  Well, why is it any different from other fields? From one of your
  examples [1], I'd expect you to have a list of questions in the Quiz data
  type, and if necessary, a quiz field in the Question data type. This might
  be a bit tricky but certainly achievable [2].

 This is really tricky. For example, consider storing a large tree in the
 database:

  data Tree = Node Int Tree Tree | Leaf Int

 This means you need to read the entire tree from the database. Or consider
 cyclic datastructures (such as the example you gave). How do you store this?
 The only way to inspect this is using a library like data-reify [1].

 I think the problem might be a bit harder than you suspect.

 Another way to solve it is using Sebastiaan Visser's framework, described
 in his paper [2], but that's also rather complicated.

 -chris

 [1]: http://hackage.haskell.org/package/data-reify
 [2]:
 http://github.com/downloads/sebastiaanvisser/msc-thesis/wgp10-genstorage.pdf


 --
 Ozgur Akgun

 ___
 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] ICFP2010 contest results?

2010-09-29 Thread Malcolm Wallace

Ryan Ingram wrote:


I saw the winner was announced.  Is there a highscore table?  We were
in the top 5, I want to see how well we did.


Only the winners were announced at the conference - no highscore  
table.  The organisers may put more detail on the contest website  
perhaps?


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


[Haskell-cafe] Re: Parsec question (new user): unexpected end of input

2010-09-29 Thread Christian Maeder
Am 29.09.2010 11:55, schrieb Christian Maeder:
 Am 29.09.2010 09:54, schrieb Christian Maeder:
 Am 29.09.2010 05:35, schrieb Peter Schmitz:
 [...]
 Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1):
 unexpected end of input
 expecting 

 The input was:
 [...]

 -- Parsers:
 taggedContent = do
optionalWhiteSpace
aTag
many tagOrContent
aTag

 many tagOrContent will consume all tags, so that no tag for the
 following aTag will be left.
 
 if you want to match a final tag, you could try:
 
   manyTill tagOrContent (try (aTag  eof))

better yet, avoiding backtracking, return different things for aTag and
someContents and check if the last entry is a tag.

  tagOrContent = fmap Left aTag | fmap Right someContent

  taggedContent = do
   spaces
   aTag
   l - many tagOrContent
   eof
   case reverse l of
 Left _ : _ - return ()
 _ - fail expected final tag before EOF

C.


 Cheers Christian

eof
return Parse complete.

 tagOrContent = aTag | someContent ? tagOrContent

 aTag = do
tagBegin
xs - many (noneOf [tagEndChar])
 
 this also looks like manyTill anyChar tagEnd
 
 C.
 
tagEnd
optionalWhiteSpace
return ()

 someContent = do
manyTill anyChar tagBegin
return ()

 optionalWhiteSpace = spaces   -- i.e., any of  \v\f\t\r\n
 tagBegin = char tagBeginChar
 tagEnd = char tagEndChar

 -- Etc:
 tagBeginChar = ''
 tagEndChar = ''

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


Re: [Haskell-cafe] Web application framework comparison?

2010-09-29 Thread Christopher Done
On 28 September 2010 21:12, Jeremy Shaw jer...@n-heptane.com wrote:
 Not sure what that means. But I am only willing to maintain so many
 wiki pages. So far at least three have come up in this thread.

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


[Haskell-cafe] Announce: lhae-0.0.3

2010-09-29 Thread Alexander Bau

lhae[1] is a spreadsheet program. It features a simple formula language 
and some basic statistical methods, like descriptive statistics and pivot
tables. 

0.0.2 - 0.0.3:
---

Improvements:
- Right click menu at columns/row headers and cells
- Insert rows/columns between exisiting rows/columns
- Boolean values
- New functions: ==,/=,,=,,=,not
- If-then-else expressions
- New constants: true,false,pi
- Filtering of columns/rows
- Relative references
- Copy formulas into multiple cells

Fixed bugs:
- Import from csv files
- Table updates when deleting/inserting rows/columns
- When closing tables: no more Want to save? queries on already saved  
tables

[1] http://hackage.haskell.org/package/lhae

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


[Haskell-cafe] ANN: collada-output-0.1

2010-09-29 Thread Tillmann Vogt

 A new graphics library:

http://hackage.haskell.org/package/collada-output

Most of the graphics libraries on hackage use OpenGL to visualize 3d 
objects.
With this library you now have the choice to use an external tool for 
visualization and enjoy the flexibility of
a standard format for 3d data exchange. I.e. one could generate a 
raytraced animation or
load the objects in a game engine. I think that the generation of 3d 
objects can be much more powerful

and elegant than in other languages.
Since this library can be an output for some other libraries on hackage,
I would agree to various changes to achieve composability of libraries.

Cheers,
Tillmann




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


[Haskell-cafe] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread caseyh

I still cannot seem to get a GUI working under Windows.

For Haskell GUI's is Ubuntu easier to setup.

If so, we're losing people if Haskell GUI's are so hard to get working  
under Windows.



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


[Haskell-cafe] A parsec question

2010-09-29 Thread Ben Franksen
I have a question about Parsec. The following program

 import Control.Applicative ((*),(*))
 import Text.Parsec
 import Text.Parsec.Char
 block p = char '{' * p * char '}'
 parser = block (many digit)
 main = parseTest parser {123a}

gives the output

  parse error at (line 1, column 5):
  unexpected a
  expecting }

Note the last line mentions only '}'. I would rather like to see

  expecting } or digit

since the parser could very well accept another digit here.

(1) What is the reason for this behaviour?
(2) Is there another combinator that behaves as I would like?
(3) Otherwise, how do I write one myself?

BTW, I am using parsec-3.1.0 and ghc-6.12.3.

Cheers
Ben

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


[Haskell-cafe] can't find in hayoo

2010-09-29 Thread Roderick Ford

I need the trick to get from 

ByteString - [GHC.Word.Word8]

and Hayoo is not helping.

 

Super simple I expected.  I haven't even tried to compile it yet.

I am just trying to read in the bytes and encode with base64:

 

import Codec.Binary.Base64
import Data.ByteString
import System.Directory
import System.Environment

main :: do
args - getArgs
bFileExist - System.Directory.doesFileExist (args !! 0)
let bytedata = --ByteString - [GHC.Word.Word8]
if bFileExist then putStrLn $ Codec.Binary.Base64.encode bytedata
else putStrlLn (File does not exist:  ++ (args !! 0))
return ()
  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] can't find in hayoo

2010-09-29 Thread Antoine Latter
On Wed, Sep 29, 2010 at 11:03 AM, Roderick Ford develo...@live.com wrote:
 I need the trick to get from
 ByteString - [GHC.Word.Word8]
 and Hayoo is not helping.

 Super simple I expected.  I haven't even tried to compile it yet.
 I am just trying to read in the bytes and encode with base64:

 import Codec.Binary.Base64
 import Data.ByteString
 import System.Directory
 import System.Environment
 main :: do
     args - getArgs
 bFileExist - System.Directory.doesFileExist (args !! 0)
 let bytedata = --ByteString - [GHC.Word.Word8]
 if bFileExist then putStrLn $ Codec.Binary.Base64.encode bytedata
 else putStrlLn (File does not exist:  ++ (args !! 0))
 return ()


Does 'unpack' do what you want?

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


Re: [Haskell-cafe] can't find in hayoo

2010-09-29 Thread Thomas DuBuisson
By and large hayoo is the alta-vista of Haskell search - it has a huge
database but isn't well organized or good at prioritizing.  Use Hoogle
when doing type-based searches for functions in the typical GHC load.

http://haskell.org/hoogle/?hoogle=%3A%3A+ByteString+-%3E+[Word8]

Also, what's with the non-standard module specification
GHC.Word.Word8?  You should use Data.Word.

Cheers,
Thomas

On Wed, Sep 29, 2010 at 9:03 AM, Roderick Ford develo...@live.com wrote:
 ByteString - [GHC.Word.Word8]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] can't find in hayoo

2010-09-29 Thread Roderick Ford

The idea was to go from

Prelude :t Data.ByteString.readFile
Data.ByteString.readFile
  :: FilePath - IO Data.ByteString.Internal.ByteString

 

to here
Prelude :t Codec.Binary.Base64.encode
Codec.Binary.Base64.encode :: [GHC.Word.Word8] - String
 

unless there is another/easier way

 

Roderick

 
 Date: Wed, 29 Sep 2010 09:23:37 -0700
 Subject: Re: [Haskell-cafe] can't find in hayoo
 From: thomas.dubuis...@gmail.com
 To: develo...@live.com
 CC: haskell-cafe@haskell.org
 
 By and large hayoo is the alta-vista of Haskell search - it has a huge
 database but isn't well organized or good at prioritizing. Use Hoogle
 when doing type-based searches for functions in the typical GHC load.
 
 http://haskell.org/hoogle/?hoogle=%3A%3A+ByteString+-%3E+[Word8]
 
 Also, what's with the non-standard module specification
 GHC.Word.Word8? You should use Data.Word.
 
 Cheers,
 Thomas
 
 On Wed, Sep 29, 2010 at 9:03 AM, Roderick Ford develo...@live.com wrote:
  ByteString - [GHC.Word.Word8]
  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] can't find in hayoo

2010-09-29 Thread Thomas DuBuisson
In addition to hoogle I suggest you check out hackage too.  I think
you'll be particularly interested in base64-bytestring:

http://hackage.haskell.org/package/base64-bytestring

Cheers,
Thomas

On Wed, Sep 29, 2010 at 9:41 AM, Roderick Ford develo...@live.com wrote:
 The idea was to go from
 Prelude :t Data.ByteString.readFile
 Data.ByteString.readFile
   :: FilePath - IO Data.ByteString.Internal.ByteString

 to here
 Prelude :t Codec.Binary.Base64.encode
 Codec.Binary.Base64.encode :: [GHC.Word.Word8] - String

 unless there is another/easier way

 Roderick

 Date: Wed, 29 Sep 2010 09:23:37 -0700
 Subject: Re: [Haskell-cafe] can't find in hayoo
 From: thomas.dubuis...@gmail.com
 To: develo...@live.com
 CC: haskell-cafe@haskell.org

 By and large hayoo is the alta-vista of Haskell search - it has a huge
 database but isn't well organized or good at prioritizing. Use Hoogle
 when doing type-based searches for functions in the typical GHC load.

 http://haskell.org/hoogle/?hoogle=%3A%3A+ByteString+-%3E+[Word8]

 Also, what's with the non-standard module specification
 GHC.Word.Word8? You should use Data.Word.

 Cheers,
 Thomas

 On Wed, Sep 29, 2010 at 9:03 AM, Roderick Ford develo...@live.com wrote:
  ByteString - [GHC.Word.Word8]

 ___
 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] can't find in hayoo

2010-09-29 Thread Roderick Ford

YES!! Thank you so much.  

And thanks to Thomas also for the suggestion of using Data.ByteString.Base64 
... as the alternative method.

 

Cheers,

Roderick
 
 Date: Wed, 29 Sep 2010 11:11:01 -0500
 Subject: Re: [Haskell-cafe] can't find in hayoo
 From: aslat...@gmail.com
 To: develo...@live.com
 CC: haskell-cafe@haskell.org
 
 On Wed, Sep 29, 2010 at 11:03 AM, Roderick Ford develo...@live.com wrote:
  I need the trick to get from
  ByteString - [GHC.Word.Word8]
  and Hayoo is not helping.
 
  Super simple I expected.  I haven't even tried to compile it yet.
  I am just trying to read in the bytes and encode with base64:
 
  import Codec.Binary.Base64
  import Data.ByteString
  import System.Directory
  import System.Environment
  main :: do
  args - getArgs
  bFileExist - System.Directory.doesFileExist (args !! 0)
  let bytedata = --ByteString - [GHC.Word.Word8]
  if bFileExist then putStrLn $ Codec.Binary.Base64.encode bytedata
  else putStrlLn (File does not exist:  ++ (args !! 0))
  return ()
 
 
 Does 'unpack' do what you want?
 
 Antoine
  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: A parsec question

2010-09-29 Thread Ben Franksen
Ben Franksen wrote:
 import Control.Applicative ((*),(*))
 import Text.Parsec
 import Text.Parsec.Char
 block p = char '{' * p * char '}'
 parser = block (many digit)
 main = parseTest parser {123a}
 
 gives the output
 
   parse error at (line 1, column 5):
   unexpected a
   expecting }
 
 Note the last line mentions only '}'. I would rather like to see
 
   expecting } or digit
 
 since the parser could very well accept another digit here.
 
 (1) What is the reason for this behaviour?
 (2) Is there another combinator that behaves as I would like?
 (3) Otherwise, how do I write one myself?

I just saw that Christian Maeder answered a similar question recently. I
tried his suggestion of using manyTill and bingo:

 {-# LANGUAGE NoMonomorphismRestriction #-}
 import Control.Applicative ((*),(*))
 import Text.Parsec
 block p = char '{' * p * char '}'
 parser = block (manyTill digit (char '}'))
 main = parseTest parser {123a}

gives

  parse error at (line 1, column 5):
  unexpected a
  expecting } or digit

So far so good. I wonder whether this parser is as efficient as the original
one. Also, this style is less modular, as I have to mention the terminator
in two places. Is there a non-greedy variant of 'many' so that modularity
gets restored and efficiency is not lost?

Cheers
Ben

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


[Haskell-cafe] Distribution needs

2010-09-29 Thread Joachim Breitner
Hi,

on planet.debian.org, there is some ill-tempered discussion about the
seemingly bad relationship between the Ruby community and Debian
maintainers. The following blog post summarizes the issues quite well
and calmly:
http://gwolf.org/blog/ruby-dissonance-debian-again

With the Haskell community, luckily the relationship is much better. But
since the technical situation is similar, i.e. a custom distribution
channel via hackage/cabal-install, the possibility to install multiple
versions of a package at once, I thought this might still be an
interesting read. I hope this improves the understanding of a
distribution’s needs and why we don’t like multiple versions of one
package or a splitting in too many single small packages.

But let me stress that I’m very happy with the interaction of the
communities,

Greetings,
Joachim

-- 
Joachim nomeata Breitner
  mail: m...@joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
  JID: nome...@joachim-breitner.de | http://www.joachim-breitner.de/
  Debian Developer: nome...@debian.org


signature.asc
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: A parsec question

2010-09-29 Thread Daniel Fischer
On Wednesday 29 September 2010 19:10:22, Ben Franksen wrote:
 
  Note the last line mentions only '}'. I would rather like to see
 
expecting } or digit
 
  since the parser could very well accept another digit here.

parsec2 did that, I don't know whether that change is intentional or 
accidental.

 
  (1) What is the reason for this behaviour?
  (2) Is there another combinator that behaves as I would like?
  (3) Otherwise, how do I write one myself?

 I just saw that Christian Maeder answered a similar question recently. I

 tried his suggestion of using manyTill and bingo:
  {-# LANGUAGE NoMonomorphismRestriction #-}
  import Control.Applicative ((*),(*))
  import Text.Parsec
  block p = char '{' * p * char '}'
  parser = block (manyTill digit (char '}'))
  main = parseTest parser {123a}

 gives

   parse error at (line 1, column 5):
   unexpected a
   expecting } or digit

 So far so good. I wonder whether this parser is as efficient as the
 original one.

manyTill p end  = scan
where
  scan  = do{ end; return [] }
|
  do{ x - p; xs - scan; return (x:xs) }

I'm not sure, but I suspect it's less efficient.

Perhaps

manyTill' p end = scan []
where
  scan acc = do { end; return (reverse acc) }
| do { x - p; scan (x:acc) }

is more efficient (depends on Parsec's bind which is more efficient), you 
could test.

 Also, this style is less modular, as I have to mention the
 terminator in two places.

That's not the main problem. `manyTill' consumes the ending token, so

block (manyTill whatever (char '}')) needs two '}' to succeed.
You would need

block (manyTill digit (lookAhead (char '}'))

to replicate the behaviour of block (many digit).

 Is there a non-greedy variant of 'many' so
 that modularity gets restored and efficiency is not lost?

 Cheers
 Ben

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


Re: [Haskell-cafe] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread JP Moresmau
There are issues, yes, and you may need the MinGW tool chain to get the GUI
packages to build and install properly, but it does work. I have blogged
about some of my experiences, both good and bad, at
http://jpmoresmau.blogspot.com/. What GUI tool specifically do you want to
use?

JP

On Wed, Sep 29, 2010 at 5:01 PM, cas...@istar.ca wrote:

 I still cannot seem to get a GUI working under Windows.

 For Haskell GUI's is Ubuntu easier to setup.

 If so, we're losing people if Haskell GUI's are so hard to get working
 under Windows.


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




-- 
JP Moresmau
http://jpmoresmau.blogspot.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread Christopher Done
On 29 September 2010 17:01,  cas...@istar.ca wrote:
 I still cannot seem to get a GUI working under Windows.

 For Haskell GUI's is Ubuntu easier to setup.

 If so, we're losing people if Haskell GUI's are so hard to get working under
 Windows.

We're losing people! Charge!

I think the problem is lack of Windows developers interested in GUIs,
and that Windows is not so POSIXy-development-friendly as Linux or OS
X. But mostly lack of people interested in that area, I think.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Monad instance for partially applied type constructor?

2010-09-29 Thread DavidA
Hi,

I have the following code:

{-# LANGUAGE TypeSynonymInstances #-}

data Vect k b = V [(k,b)]
-- vector space over field k with basis b
-- for example, V [(5, E 1), (7, E 2)] would represent the vector 5 e1 + 7 e2

data Monomial v = M [(v,Int)]
-- monomials over variables v
-- for example, M [(A,3), (B,5)] would represent the monomial a^3 b^5

type Poly k v = Vect k (Monomial v)
-- multivariate polynomials over field k and variables v

instance Monad (Poly k) where
return v = V [(1, M [(v,1)])]
p = f = ... -- variable substitution

So my thinking is:
1. The Monad type class is for one parameter type constructors (eg [], IO)
2. Poly is a two-parameter type constructor
3. So Poly k is a one-parameter type constructor
4. What I'm trying to express, that polynomials over field k are a monad,
is true.

However, GHC 6.12.2 complains:

Type synonym `Poly' should have 2 arguments, but has been given 1
In the instance declaration for `Monad (Poly k)'

What is going wrong?


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


Re: [Haskell-cafe] Monad instance for partially applied type constructor?

2010-09-29 Thread Christopher Done
Maybe -XLiberalTypeSynonyms is an option:
http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/data-type-extensions.html#type-synonyms

On 29 September 2010 20:08, DavidA polyom...@f2s.com wrote:
 Hi,

 I have the following code:

 {-# LANGUAGE TypeSynonymInstances #-}

 data Vect k b = V [(k,b)]
 -- vector space over field k with basis b
 -- for example, V [(5, E 1), (7, E 2)] would represent the vector 5 e1 + 7 e2

 data Monomial v = M [(v,Int)]
 -- monomials over variables v
 -- for example, M [(A,3), (B,5)] would represent the monomial a^3 b^5

 type Poly k v = Vect k (Monomial v)
 -- multivariate polynomials over field k and variables v

 instance Monad (Poly k) where
    return v = V [(1, M [(v,1)])]
    p = f = ... -- variable substitution

 So my thinking is:
 1. The Monad type class is for one parameter type constructors (eg [], IO)
 2. Poly is a two-parameter type constructor
 3. So Poly k is a one-parameter type constructor
 4. What I'm trying to express, that polynomials over field k are a monad,
 is true.

 However, GHC 6.12.2 complains:

    Type synonym `Poly' should have 2 arguments, but has been given 1
    In the instance declaration for `Monad (Poly k)'

 What is going wrong?


 ___
 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] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread Steve Schafer
On Wed, 29 Sep 2010 20:08:07 +0200, you wrote:

I think the problem is lack of Windows developers interested in GUIs,
and that Windows is not so POSIXy-development-friendly as Linux or OS
X. But mostly lack of people interested in that area, I think.

There are lots of Windows developers interested in GUIs. On the whole,
I'd say that Windows developers are far more focused on GUIs than
non-Windows developers. (See, for example:

 http://mpt.net.nz/archive/2008/08/01/free-software-usability

and

 http://daringfireball.net/2004/04/spray_on_usability

for some discussion of attitudes.)

The issue isn't that there aren't a lot of Windows developers who have
an interest in Haskell+GUI development. The issue is that nearly every
Windows developer who looks into Haskell+GUI says, This stuff sucks,
and walks away, because they're interested in developing applications,
not wrestling with GUI toolkits.

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


Re: [Haskell-cafe] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread aditya siram
I imagine that getting Haskell GUI libraries set and playing nice with
the native GTK libs is a pain on Windows.

That said, I know that Haskell has very nice Lua bindings and Lua has
pretty mature GTK bindings. Has anyone tried developing their UI in
Lua with Haskell doing all the heavy lifting?

-deech

On Wed, Sep 29, 2010 at 1:33 PM, Steve Schafer st...@fenestra.com wrote:
 On Wed, 29 Sep 2010 20:08:07 +0200, you wrote:

I think the problem is lack of Windows developers interested in GUIs,
and that Windows is not so POSIXy-development-friendly as Linux or OS
X. But mostly lack of people interested in that area, I think.

 There are lots of Windows developers interested in GUIs. On the whole,
 I'd say that Windows developers are far more focused on GUIs than
 non-Windows developers. (See, for example:

  http://mpt.net.nz/archive/2008/08/01/free-software-usability

 and

  http://daringfireball.net/2004/04/spray_on_usability

 for some discussion of attitudes.)

 The issue isn't that there aren't a lot of Windows developers who have
 an interest in Haskell+GUI development. The issue is that nearly every
 Windows developer who looks into Haskell+GUI says, This stuff sucks,
 and walks away, because they're interested in developing applications,
 not wrestling with GUI toolkits.

 -Steve Schafer
 ___
 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] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread Christopher Done
On 29 September 2010 20:33, Steve Schafer st...@fenestra.com wrote:
 There are lots of Windows developers interested in GUIs. [..]

 The issue isn't that there aren't a lot of Windows developers who have
 an interest in Haskell+GUI development.

Yeah, what do you think I meant? We're talking about the state of
Haskell GUI libraries, naturally I'm talking about Haskell GUI
developers. Of course Windows developers are obsessed with GUIs, I
can't get anything done in a terminal on Windows. (I'm exaggerating.)

 The issue is that nearly every
 Windows developer who looks into Haskell+GUI says, This stuff sucks,
 and walks away, because they're interested in developing applications,
 not wrestling with GUI toolkits.

Yeah, but not liking wrestling with libraries isn't peculiar to
Haskell developers. There just needs to be enough people that the
probability of there being a person who will bother to wrestle with it
is high enough. Hence, the issue is lack of interest.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad instance for partially applied type constructor?

2010-09-29 Thread Ryan Ingram
On Wed, Sep 29, 2010 at 11:08 AM, DavidA polyom...@f2s.com wrote:
 Hi,

 I have the following code:

 {-# LANGUAGE TypeSynonymInstances #-}

 data Vect k b = V [(k,b)]
 -- vector space over field k with basis b
 -- for example, V [(5, E 1), (7, E 2)] would represent the vector 5 e1 + 7 e2

 data Monomial v = M [(v,Int)]
 -- monomials over variables v
 -- for example, M [(A,3), (B,5)] would represent the monomial a^3 b^5

 type Poly k v = Vect k (Monomial v)
 -- multivariate polynomials over field k and variables v

 instance Monad (Poly k) where
    return v = V [(1, M [(v,1)])]
    p = f = ... -- variable substitution

 So my thinking is:
 1. The Monad type class is for one parameter type constructors (eg [], IO)
 2. Poly is a two-parameter type constructor
 3. So Poly k is a one-parameter type constructor
 4. What I'm trying to express, that polynomials over field k are a monad,
 is true.

 However, GHC 6.12.2 complains:

    Type synonym `Poly' should have 2 arguments, but has been given 1
    In the instance declaration for `Monad (Poly k)'

 What is going wrong?

Haskell doesn't have true type functions; what you are really saying is

instance Monad (\v - Vect k (Monomial v))

TypeSynonymInstances just lets you write stuff like this

type Foo = [Int]
instance C Foo where ...

instead of

type Foo = [Int]
instance C [Int] where ...

But it doesn't let you partially apply the type synonym.

On the other hand, if you did this:

newtype Compose f g a = O { unO :: f (g a) }
type Poly k = Compose (Vect k) Monomial

instance Monad (Poly k) where ...

would work, but now you have to wrap/unwrap Compose in the instance definition.

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


Re: [Haskell-cafe] Monad instance for partially applied type constructor?

2010-09-29 Thread Christopher Done
On 29 September 2010 20:48, Ryan Ingram ryani.s...@gmail.com wrote:
 But it doesn't let you partially apply the type synonym.

 On the other hand, if you did this:

 newtype Compose f g a = O { unO :: f (g a) }
 type Poly k = Compose (Vect k) Monomial

 instance Monad (Poly k) where ...

 would work, but now you have to wrap/unwrap Compose in the instance 
 definition.

LiberalTypeSynonyms lets you partially apply type synonyms.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad instance for partially applied type constructor?

2010-09-29 Thread Dan Doel
On Wednesday 29 September 2010 2:52:21 pm Christopher Done wrote:
 LiberalTypeSynonyms lets you partially apply type synonyms.

Not in general. LiberalTypeSynonyms only allows synonyms to be partially 
applied when expansions of other type synonyms will eventually cause them to 
become fully applied (or discarded, probably). So, for instance:

  type Foo a = (a, a)
  type Bar f = f Int

  Bar Foo == Foo Int == (Int, Int) -- valid

It does not make partially applied synonyms first class, such that they'd be 
able to be made instances, or parameters to datatypes, etc.

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


Re: [Haskell-cafe] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread Steve Schafer
On Wed, 29 Sep 2010 20:44:22 +0200, you wrote:

Yeah, but not liking wrestling with libraries isn't peculiar to
Haskell developers. There just needs to be enough people that the
probability of there being a person who will bother to wrestle with it
is high enough. Hence, the issue is lack of interest.

No, it isn't peculiar to Haskell developers; the problem is the one that
is discussed in more detail in the two references I gave in my previous
message: For the most part, developers who are attracted to open-source
projects (and this certainly includes the majority of Haskell
developers) simply don't think much of GUIs, and are consequently
willing to release software with half-baked GUI support (at best).

This is an attitude that just doesn't fly in the Windows world. Which is
unfortunate, because the Windows market is HUGE compared to OS X, and
STUNNINGLY HUGE compared to everything else.

The fix isn't going to be to find a developer who's willing to do the
work to make Haskell+GUI more seamless under Windows. The fix is for the
Haskell community--as a whole--to wake up and realize what the wxWidgets
folks did a while ago: Hey, you know what? This GUI stuff is
_important_ if we want people to pay any attention to the software that
we write!

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


Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-29 Thread Henning Thielemann
S. Doaitse Swierstra schrieb:
 Avoiding repeated additions:
 
 movingAverage :: Int - [Float] - [Float]
 movingAverage n l = runSums (sum . take n $l) l (drop n l)
  where n' = fromIntegral n
runSums sum (h:hs) (t:ts) = sum / n' : runSums (sum-h+t) hs ts
runSums _   _ []  = []

Moving average can be interpreted as convolution (*):
[1/n,1/n,1/n,...,1/n] * xs

You may drop the first (n-1) values, since they average over initial
padding zeros.

Convolution is associative and you can decompose the first operand into
simpler parts:

1/n · [1,1,1,...] * [1,0,0,,0,0,-1] * xs
 = 1/n · integrate ([1,0,0,,0,0,-1] * xs)

Convolution is commutative, thus you could also write
 = 1/n · [1,0,0,,0,0,-1] * integrate xs
 but then integration of xs will yield unbounded values and thus higher
rounding errors.

This yields:

movingAverage :: Int - [Float] - [Float]
movingAverage n =
   drop (n-1) .
   map (/ fromIntegral n) .
   scanl1 (+) .
   (\xs - zipWith (-) xs (replicate n 0 ++ xs))

This should be the same as the implementation above, but maybe a bit
nicer. :-)

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


Re: [Haskell-cafe] Coding conventions for Haskell?

2010-09-29 Thread Andrew Coppin

 On 29/09/2010 02:18 PM, Henning Thielemann wrote:

Andrew Coppin wrote:

Tastes do indeed vary. To me, both of these are incorrect, and the 
correct way is


  data Foo a b =
  Fooa   |
  Bar  b |
  Foobar a b
deriving (Eq, Ord)


The truth is: Given the separator style of constructor definition, 
there is no correct way to format those declarations. :-) The correct 
way would be to allow terminator style.


Well, yes, there is that. (And this isn't the only place in the syntax 
where it applies either. Tried editing export lists lately? Or Cabal 
module lists?)


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


[Haskell-cafe] Re: Re: A parsec question

2010-09-29 Thread Ben Franksen
Daniel Fischer wrote:
 On Wednesday 29 September 2010 19:10:22, Ben Franksen wrote:
 
  Note the last line mentions only '}'. I would rather like to see
 
expecting } or digit
 
  since the parser could very well accept another digit here.
 
 parsec2 did that, I don't know whether that change is intentional or
 accidental.

This looks more like a bug than a feature to me. I checked parsec-3.0.1 and
it behaves like parsec-2, i.e. behaves as I expected.

  (1) What is the reason for this behaviour?
  (2) Is there another combinator that behaves as I would like?
  (3) Otherwise, how do I write one myself?

 I just saw that Christian Maeder answered a similar question recently. I

 tried his suggestion of using manyTill and bingo:
  {-# LANGUAGE NoMonomorphismRestriction #-}
  import Control.Applicative ((*),(*))
  import Text.Parsec
  block p = char '{' * p * char '}'
  parser = block (manyTill digit (char '}'))
  main = parseTest parser {123a}
 You would need
 
 block (manyTill digit (lookAhead (char '}'))
 
 to replicate the behaviour of block (many digit).

Right, so it gets even more complicated.

 Is there a non-greedy variant of 'many' so
 that modularity gets restored and efficiency is not lost?

So many questions...

Cheers
Ben

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


Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-29 Thread S. Doaitse Swierstra

On 29 sep 2010, at 00:58, o...@cs.otago.ac.nz wrote:

 Avoiding repeated additions:
 
 movingAverage :: Int - [Float] - [Float]
 movingAverage n l = runSums (sum . take n $l) l (drop n l)
 where n' = fromIntegral n
   runSums sum (h:hs) (t:ts) = sum / n' : runSums (sum-h+t) hs ts
   runSums _   _ []  = []
 
 Doaitse
 
 I very very carefully avoided doing any such thing in my example code.
 For each output result, my code does two additions and one division.
 Yours does one addition, one subtraction, and one division, for the
 required case n = 3.  The way I formulated it, each calculation is
 independent.  The way you've formulated it, the error in one
 calculation accumulates into the next.  NOT a good idea.

If this an issue then:

module MovingAverage where

movingAverage :: [Float] - [Float]
movingAverage (x:y:l) = movingAverage' x y l
where movingAverage' x y (z:zs) = (x+y+z)/3:movingAverage' y z zs
  movingAverage' _ _ _  = []
movingAverage _   = []


has far fewer pattern matches,

 Doaitse


 
 

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


Re: [Haskell-cafe] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread Andrew Coppin

 On 29/09/2010 07:33 PM, Steve Schafer wrote:

The issue isn't that there aren't a lot of Windows developers who have
an interest in Haskell+GUI development. The issue is that nearly every
Windows developer who looks into Haskell+GUI says, This stuff sucks,
and walks away, because they're interested in developing applications,
not wrestling with GUI toolkits.


Yep, that's the one.

If you want to build a GUI application in Tcl, it's going to take a 
couple of minutes to throw together some Tk commands and you're done. In 
Java, you'll have to write a mile of boilerplate, but there are wizzy 
tools that will write it for you. And I gather that if you've coding in 
C or C++ or C#, you can use VisualStudio to throw a complex GUI together 
in a couple of minutes.


How do you do that in Haskell? Well, you can either install and 
configure a complete Unix emulator and then compile wxHaskell from 
source (?!), or you can use Gtk2hs, which still requires you to manually 
install and configure GTK+ and compile the entire library from source 
code. And even then, your developed application will only run on Windows 
boxes that have GTK+ installed (i.e., none of them). All of which is a 
far cry from install IDE, click some buttons, run the wizzard, job done.


Then again, let us not claim that this is only a problem for GUI stuff. 
If you want to access a database, or run compression algorithms, or play 
sound, or do absolutely anything else which requires talking to C-land, 
you've going to have to face a world of pain on Windows.


It seems that because this stuff is such a PITA on Windows, nobody uses 
Haskell on Windows. And since nobody uses Haskell on Windows, nobody is 
fixing these problems. So they just stay here, forever.


So anyway, that's the problem. The solution is...

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


Re: [Haskell-cafe] Retargeting Haskell compiler to embedded/hardware

2010-09-29 Thread Atze Dijkstra
Hi Tom,

The Utrecht Haskell Compiler (UHC) is internally organized as a set of 
compilers, for which you can configure the aspects you want. It is relatively 
easy to extract such a particular combination and use it as a starting point. 
Or you might install UHC itself and use the installed libraries, which include 
abstract syntax, parser, etc. There is some variation depending on what you 
need, so check out http://www.cs.uu.nl/wiki/UHC for initial reading, and let me 
know whether you need more info.

regards,

On  29 Sep, 2010, at 16:49 , S. Doaitse Swierstra wrote:

 
 
 Begin forwarded message:
 
 From: Tom Hawkins tomahawk...@gmail.com
 Date: 29 september 2010 03:58:11 GMT+02:00
 To: haskell-cafe haskell-cafe@haskell.org
 Subject: [Haskell-cafe] Retargeting Haskell compiler to embedded/hardware
 
 A few years ago I attempted to build a Haskell hardware compiler
 (Haskell - Verilog) based on the Yhc frontent.  At the time I was
 trying to overcome several problems [1] with implementing a hardware
 description language as a light eDSL, which convinced me a proper
 compiler may be a better approach.  Yhc was recommended as a good
 starting point since it had a simpler IR compared with GHC -- at least
 at the time.
 
 I am considering restarting this effort, but this time to target hard
 realtime embedded code.  What is the recommended compiler to start
 from?  I need an IR that is post type checking with as much desugaring
 as possible, and a code base that is relatively easy to splice and
 build.
 
 My other requirement is not to be bound to IO () for 'main'.  The top
 level will be a monad, but with different semantics than IO.  I would
 also like to reuse the standard library, with exception to the values
 related to IO.
 
 What are my options?
 
 Thanks.
 
 -Tom
 
 [1] Lack of observable sharing; function definitions, case
 expressions, ADTs disappear at compile time; etc.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 


- Atze -

Atze Dijkstra, Department of Information and Computing Sciences. /|\
Utrecht University, PO Box 80089, 3508 TB Utrecht, Netherlands. / | \
Tel.: +31-30-2534118/1454 | WWW  : http://www.cs.uu.nl/~atze . /--|  \
Fax : +31-30-2513971  | Email: a...@cs.uu.nl  /   |___\



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


[Haskell-cafe] Re: Monad instance for partially applied type constructor?

2010-09-29 Thread DavidA
Ryan Ingram ryani.spam at gmail.com writes:

 Haskell doesn't have true type functions; what you are really saying is
 
 instance Monad (\v - Vect k (Monomial v))
 

Yes, that is exactly what I am trying to say. And since I'm not allowed to say
it like that, I was trying to say it using a type synonym parameterised over v
instead. It appears that GHC won't let you use partially applied type synonyms
as type constructors for instance declarations. Is this simply because the GHC
developers didn't think anyone would want to, or is there some theoretical
reason why it's hard, or a bad idea?


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


Re: [Haskell-cafe] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread Daniel Fischer
On Wednesday 29 September 2010 23:02:02, Andrew Coppin wrote:
 So anyway, that's the problem. The solution is...

Two obvious solutions.
- stop using Windows and migrate to an OS where stuff works pretty much out 
of the box (not going to happen a lot)
- start helping to make things work on Windows (maybe someday that will 
happen)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Monad instance for partially applied type constructor?

2010-09-29 Thread Daniel Fischer
On Wednesday 29 September 2010 23:15:14, DavidA wrote:
 Ryan Ingram ryani.spam at gmail.com writes:
  Haskell doesn't have true type functions; what you are really saying
  is
 
  instance Monad (\v - Vect k (Monomial v))

 Yes, that is exactly what I am trying to say. And since I'm not allowed
 to say it like that, I was trying to say it using a type synonym
 parameterised over v instead. It appears that GHC won't let you use
 partially applied type synonyms as type constructors for instance
 declarations. Is this simply because the GHC developers didn't think
 anyone would want to, or is there some theoretical reason why it's hard,
 or a bad idea?


I think there was a theoretical reason why that isn't allowed (making type 
inference undecidable? I don't remember, I don't recall ...).

For your problem, maybe

data Vect k m b = Vect [(k, m b)]

instance Monad (Vect k Monomial) where ...

is an option?

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


Re: [Haskell-cafe] Re: Monad instance for partially applied type constructor?

2010-09-29 Thread Ryan Ingram
It's hard.  Here's a simple example:

type Foo f = f Int

class C (f :: (* - *) - *) where
   thingy :: f [] - f IO

-- Should this ever typecheck?  I would say no; there's no way to
unify f [] with [Int].
callThingy :: [Int] - IO Int
callThingy = thingy

-- but what if you say this?
instance C Foo where
 -- thingy :: Foo [] - Foo IO
 -- therefore,
 -- thingy :: [Int] - IO Int
 thingy (x:_) = return x

Basically, allowing instances for type functions requires you to
*un-apply* any type functions to attempt to do instance selection.

  -- ryan

On Wed, Sep 29, 2010 at 2:15 PM, DavidA polyom...@f2s.com wrote:
 Ryan Ingram ryani.spam at gmail.com writes:

 Haskell doesn't have true type functions; what you are really saying is

 instance Monad (\v - Vect k (Monomial v))


 Yes, that is exactly what I am trying to say. And since I'm not allowed to say
 it like that, I was trying to say it using a type synonym parameterised over v
 instead. It appears that GHC won't let you use partially applied type synonyms
 as type constructors for instance declarations. Is this simply because the GHC
 developers didn't think anyone would want to, or is there some theoretical
 reason why it's hard, or a bad idea?


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

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


Re: [Haskell-cafe] Re: Monad instance for partially applied type constructor?

2010-09-29 Thread Gábor Lehel
On Wed, Sep 29, 2010 at 11:15 PM, DavidA polyom...@f2s.com wrote:
 Ryan Ingram ryani.spam at gmail.com writes:

 Haskell doesn't have true type functions; what you are really saying is

 instance Monad (\v - Vect k (Monomial v))


 Yes, that is exactly what I am trying to say. And since I'm not allowed to say
 it like that, I was trying to say it using a type synonym parameterised over v
 instead. It appears that GHC won't let you use partially applied type synonyms
 as type constructors for instance declarations. Is this simply because the GHC
 developers didn't think anyone would want to, or is there some theoretical
 reason why it's hard, or a bad idea?

The version of the lambda calculus (System Fc) GHC uses for its
internal representation doesn't support lambdas at the type level.
I've bumped up against this limitation myself, and don't know of any
way to 'cheat' it (which makes sense, given that it's so fundamental).
You can use newtypes, and recursive definitions (sometimes with
overlap and/or fundeps) work for some cases, though they can get quite
nasty in the harder ones. I have to assume upgrading the type system
to support this would highly nontrivial, though I don't know exactly
how high, nor what drawbacks there might be.




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




-- 
Work is punishment for failing to procrastinate effectively.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread Ben Franksen
Andrew Coppin wrote:
   On 29/09/2010 07:33 PM, Steve Schafer wrote:
 The issue isn't that there aren't a lot of Windows developers who have
 an interest in Haskell+GUI development. The issue is that nearly every
 Windows developer who looks into Haskell+GUI says, This stuff sucks,
 and walks away, because they're interested in developing applications,
 not wrestling with GUI toolkits.
 
 Yep, that's the one.
 
 If you want to build a GUI application in Tcl, it's going to take a
 couple of minutes to throw together some Tk commands and you're done. 

Right.

 In
 Java, you'll have to write a mile of boilerplate, but there are wizzy
 tools that will write it for you. And I gather that if you've coding in
 C or C++ or C#, you can use VisualStudio to throw a complex GUI together
 in a couple of minutes.

Not so, at least with C++. I have used VS and C++, it is horrible. Never
again.

 How do you do that in Haskell? Well, you can either install and
 configure a complete Unix emulator and then compile wxHaskell from
 source (?!), or you can use Gtk2hs, which still requires you to manually
 install and configure GTK+ and compile the entire library from source
 code. And even then, your developed application will only run on Windows
 boxes that have GTK+ installed (i.e., none of them). 

Can you not statically link the gtk libraries?

 All of which is a
 far cry from install IDE, click some buttons, run the wizzard, job done.

I never found that this actually works. Yea, you can get *something* running
pretty fast, but as soon as you start to do stuff that is not 100% standard
off-the-shelf, you are screwed. *This* is when things become *really*
difficult. All this compiling and installing libraries stuff is harmless,
compared to the problems caused by stupidly broken APIs and crippled
languages.

Cheers
Ben

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


RE: [Haskell-cafe] I still cannot seem to get a GUI working under Windows.

2010-09-29 Thread Roderick Ford

These were enough to get me started:

 

http://www.haskell.org/haskellwiki/Opengl

 

http://haskell.forkio.com/com-examples

 

http://darcs.haskell.org/packages/Win32/examples/
 

 

Roderick

 
 Date: Wed, 29 Sep 2010 11:01:50 -0400
 From: cas...@istar.ca
 To: haskell-cafe@haskell.org
 Subject: [Haskell-cafe] I still cannot seem to get a GUI working under 
 Windows.
 
 I still cannot seem to get a GUI working under Windows.
 
 For Haskell GUI's is Ubuntu easier to setup.
 
 If so, we're losing people if Haskell GUI's are so hard to get working 
 under Windows.
 
 
 ___
 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: ICFP2010 contest results?

2010-09-29 Thread Johannes Waldmann

 The organisers may put more detail on the contest website  perhaps?

Will do, after I get home from ICFP. - Best, Johannes.


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


[Haskell-cafe] When I change the cabal file to say preference: base = 4

2010-09-29 Thread caseyh

When I change the cabal file to say
preference: base = 4
I still get, you are using base 3.0 which is deprecated.
When I change the overall cabal profile, the error message still comes up.
It seems like some other part of the install process is controlling  
the base version, besides the *.cabal and cabal profile file.



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


Re: [Haskell-cafe] When I change the cabal file to say preference: base = 4

2010-09-29 Thread Daniel Fischer
On Thursday 30 September 2010 00:56:56, cas...@istar.ca wrote:
 When I change the cabal file to say
 preference: base = 4

In the .cabal file of a package, that would belong in the build-depends.

 I still get, you are using base 3.0 which is deprecated.
 When I change the overall cabal profile, the error message still comes
 up.

Which cabal version? Perhaps it doesn't know preferences yet.

 It seems like some other part of the install process is controlling
 the base version, besides the *.cabal and cabal profile file.


Did you verify that none of the build-depends requires base == 3.* ?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] When I change the cabal file to say preference: base = 4

2010-09-29 Thread Jason Dagit
On Wed, Sep 29, 2010 at 3:56 PM,  cas...@istar.ca wrote:
 When I change the cabal file to say
 preference: base = 4
 I still get, you are using base 3.0 which is deprecated.
 When I change the overall cabal profile, the error message still comes up.
 It seems like some other part of the install process is controlling the base
 version, besides the *.cabal and cabal profile file.

When you run install or configure, try passing -v to see the verbose
output.  This can often help you see why the wrong package is picked.
With base it's a bit trickier.

In theory, constraints should override preferences.  Base has a
special thing where the preference overrides constraints when the
upper bound is missing.  Does the package in question have an upper
bound on the version of base?  Something like, base == 4.*, or base 
3  base  5  ?

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


[Haskell-cafe] Re: Parsec question (new user): unexpected end of input

2010-09-29 Thread Peter Schmitz
Antoine and Christian:
Many thanks for your help on this thread.
(I am still digesting it; much appreciated; will post when I get it working.)
-- Peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Monad instance for partially applied type constructor?

2010-09-29 Thread Alexander Solla

 On 09/29/2010 02:15 PM, DavidA wrote:

instance Monad (\v -  Vect k (Monomial v))
  

Yes, that is exactly what I am trying to say. And since I'm not allowed to say
it like that, I was trying to say it using a type synonym parameterised over v
instead.


Why not:

instance Monad ((-) Vect k (Monomial v))
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Monad instance for partially applied type constructor?

2010-09-29 Thread Alexander Solla

 On 09/29/2010 09:13 PM, Alexander Solla wrote:

 On 09/29/2010 02:15 PM, DavidA wrote:

instance Monad (\v -  Vect k (Monomial v))
 
Yes, that is exactly what I am trying to say. And since I'm not 
allowed to say
it like that, I was trying to say it using a type synonym 
parameterised over v

instead.


Why not:

instance Monad ((-) Vect k (Monomial v))


Sorry, I guess this is a bit off.  I don't think you really want a 
monad.  I think you want something like the dual to the reader monad 
(i.e, a comonad)

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


Re: [Haskell-cafe] Re: Monad instance for partially applied type constructor?

2010-09-29 Thread Stefan Holdermans
David,

Ryan Ingram wrote:

 Haskell doesn't have true type functions; what you are really saying
 is
 
 instance Monad (\v - Vect k (Monomial v))

Daniel Fischer wrote:

 I think there was a theoretical reason why that isn't allowed (making type 
 inference undecidable? I don't remember, I don't recall ...).

Indeed: type inference in the presence of type-level lambdas requires 
higher-order unification, which is undecidable [1].

Cheers,

  Stefan

[1] Gérard P. Huet: The Undecidability of Unification in Third Order Logic 
Information and Control 22(3): 257-267 (1973)


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


[Haskell-cafe] Problem with a sample from RWH

2010-09-29 Thread C K Kashyap
Hi,
I was going over the Error Handling chapter in RWH and tried out this sample -

Prelude :m Control.Exception
Prelude Control.Exception let x=5 `div` 0
Prelude Control.Exception let y=5 `div` 1
Prelude Control.Exception handle (\_ - putStrLn Text) (print x)

interactive:1:0:
Ambiguous type variable `e' in the constraint:
  `Exception e'
arising from a use of `handle' at interactive:1:0-39
Probable fix: add a type signature that fixes these type variable(s)
Prelude Control.Exception

Could someone please tell me what the problem is and how to resolve it?

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


Re: [Haskell-cafe] Problem with a sample from RWH

2010-09-29 Thread Ivan Lazar Miljenovic
On 30 September 2010 15:23, C K Kashyap ckkash...@gmail.com wrote:
 Hi,
 I was going over the Error Handling chapter in RWH and tried out this sample -

 Prelude :m Control.Exception
 Prelude Control.Exception let x=5 `div` 0
 Prelude Control.Exception let y=5 `div` 1
 Prelude Control.Exception handle (\_ - putStrLn Text) (print x)

 interactive:1:0:
    Ambiguous type variable `e' in the constraint:
      `Exception e'
        arising from a use of `handle' at interactive:1:0-39
    Probable fix: add a type signature that fixes these type variable(s)
 Prelude Control.Exception

 Could someone please tell me what the problem is and how to resolve it?

RWH was written before GHC 6.10 came out, and thus is using old-style
exceptions.  As of GHC 6.10.1 with base-4, the old-style exceptions
were replaced with extensible exceptions.  As such, you have two
options:

* Keep using old-style exceptions.  With GHC 6.10 and 6.12, import
Control.OldException instead of Control.Exception
* Manually migrate the RWH code to new-style exceptions; there are two
ways of doing this:
  - For production code, you should add explicit type signatures, etc.
for your exception-handling functions passed to handle, etc.
  - For just playing around, use SomeException: e.g.: handle (\
SomeException{} - putStrLn Text) (print x)

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe