Re: [Haskell-cafe] if - then - else layout
I think it'd be nice if we just replaced the if with a question mark :) -- _jsn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Injecting Haskell into C
Anatoly I have not been following the details, but would you consider writing up your example on the GHC user guide Wiki? http://haskell.org/haskellwiki/GHC/Using_the_FFI It's a very good way to share your experience with others. Simon | -Original Message- | From: [EMAIL PROTECTED] [mailto:haskell-cafe- | [EMAIL PROTECTED] On Behalf Of Anatoly Yakovenko | Sent: 24 September 2008 22:42 | To: [EMAIL PROTECTED] | Cc: haskell | Subject: Re: [Haskell-cafe] Injecting Haskell into C | | you'll find this example really helpfull | | | -- Forwarded message -- | From: Claude Heiland-Allen [EMAIL PROTECTED] | Date: 2008/6/5 | Subject: Re: [Haskell-cafe] example of FFI FunPtr | To: Galchin, Vasili [EMAIL PROTECTED] | Cc: haskell haskell-cafe@haskell.org | | | Galchin, Vasili wrote: | | Hello, | |I want to model a Haskell function that is a callback from C. I have | only found one example in the unix package's Semaphore.hsc, which | apparently | is not used. I want to be able to marshall a Haskell function that is a | first class citizen residing in a Haskell data type and pass to a C | function | via FFI. Are there examples of this? | | Attached is a simple example. | | The main thing to note is 'foreign import ccall wrapper' which gives | you a factory for turning Haskell functions into foreign function | pointers. | | More information: | | http://www.cse.unsw.edu.au/~chak/haskell/ffi/ | | | Claude | -- | http://claudiusmaximus.goto10.org | | | CallBacker: CallBacker.hs callerback.c callerback.h |ghc -O2 -Wall -fffi -o CallBacker CallBacker.hs callerback.c | | ___ | 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] Haskell board game
Bertram has put together a peg solitaire game using gtk2hs with Prompt for control: http://int-e.home.tlink.de/haskell/solitaire.tar.gz It's a good read and probably a good starting point for other board games. -- ryan On Wed, Sep 24, 2008 at 7:04 PM, Rafael C. de Almeida [EMAIL PROTECTED] wrote: Hello, I'm interested in doing a simple board game on haskell. For that I want to be able to draw stuff like the possible player movements and I want to be able to display very simple animations. I want to know what graphical interface library you suggest to me. I have almost no prior experience with graphical interfaces of any kind, so I rather start with something easy and straightforward. I have no need for great performance or anything like that. I'd like if it runs on windows with much trouble, that is, it'll be easy to package it for windows without requiring the user to install anything besides my game. My first thought was to use GTK's gtkTable, but I'm unsure how easy it is to make it work on windows. Beside that, I'm not sure it would be the easiest API for me to use. []'s Rafael ___ 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: Am I doing it right?
Daniel Fischer [EMAIL PROTECTED] wrote: The fast searching function on ByteStrings has already been written for you :) That's in ghc 6.8.3, which is not in gentoo but only in the haskell overlay, which means that all blame goes to the gentoo maintainers for being utterly out of date. The KMP import works like a charm. findSubstring is only defined for strict bytestrings... try running those benchmarks again, this time on data bigger than your ram. Not to mention that it's deprecated. The really interesting topic is hacking Parsec to use KMP search on manyTill anyChar (try string match), or rather any recursive try involving combinators that can calculate the position for the next candidate match as a side effect. PS: Thank you for not pointing out that my original code crashes on B.tail B.empty in some cases, or even just that it can't replace overlapping matches at all. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] if - then - else layout
leledumbo wrote: consider this partial program: if n5 then putStrLn big else putStrLn small this works fine in hugs, but in ghc I must change it to: if n5 then putStrLn big else putStrLn small Actually both of those are valid expressions. And they both work in hugs and ghc. The question I imagine you're asking involves layout mode: do if n5 then putStrLn big else putStrLn small this is shorthand for do { if n 5 then putStrLn big ; else putStrLn small } which is a syntax error. A statement in a do block cannot begin with the keyword else. If you indent the else a bit further than it counts and a continuation of the enclosing expression (beginning with if) so it desugars to do { if n 5 then putStrLn big else putStrLn small } which is fine. Haskell' is apparently going to include a hack to permit this case. I think that's a poor decision, because including a hack to the layout rule makes it harder to understand and explain the layout rule. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: if - then - else layout
Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: I think Hugs is violating the Haskell98 layout rules. One could argue that GHC should, too. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Distributing Haskell binaries as OSX App Bundles
Stephen wrote: I wrote a command-line program recently for a friend in haskell. However, he's far away and not particularly computer literate. I sent him the raw binaries, but they came up with errors about not being able to find libgmp stuff. So then I thought I should probably be able to I usually link in libgmp.a statically. This happens automatically if libgmp.a resides in ghc's libdir (just copy it) Cheers Christian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: if - then - else layout
Jules Bean [EMAIL PROTECTED] wrote: do if n5 then putStrLn big else putStrLn small this is shorthand for do { if n 5 then putStrLn big ; else putStrLn small } which is a syntax error. A statement in a do block cannot begin with the keyword else. Haskell' is apparently going to include a hack to permit this case. I think that's a poor decision, because including a hack to the layout rule makes it harder to understand and explain the layout rule. There's no need to hack the layout rule, you're even giving pointers to the solution. Something like this: if p = do (_, c, a) - get put (b, c, a) mzero then c = do (b, _, a) - get put (b, c, a) mzero else a = do (b, c, _) - get put (b, c, a) mzero end = do (b, c, a) - get return if p then a else c Advantages are obvious: Order doesn't really matter anymore, as in then get away else or else if i tell you to end Furthermore, this scheme supports logical comments, a rare kind of control structure enabling mindboggingly diverse rapid prototyping options: if i knew what i want to do if i knew how to do it then i'd have written the next line much earlier if i wrote this line then i don't need to remove the other lines else where in other languages i'd have to do that end -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: if - then - else layout
Achim Schneider [EMAIL PROTECTED] wrote: if i knew how to do it Sorry, apparent mistake, besides confusing b (bool) with p (predicate): if p _ c = do (_, _, a) - get put (p, c, a) mzero -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
Marc What is this strange syntax columns = [ (trackId, conT *''Int* ) It looks like a not ended string literal unless I still have sth to learn about Haskell. Thank you J-C On Thu, Sep 25, 2008 at 12:03 AM, Marc Weber [EMAIL PROTECTED] wrote: On Wed, Sep 24, 2008 at 11:17:01PM +0200, Manlio Perillo wrote: Hi. I need a simple, concurrent safe, database, written in Haskell. A database with the interface of Data.Map would be great, since what I need to to is atomically increment some integer values, and I would like to avoid to use SQLite. I've tried writing at least part of that. But it's still higly experimental and uses template haskell. It looks like this: from that some datastructures are defined which look like tables used in traditional RDBMS such as SQLite.. However if you don't want to use many tables you may be a lot faster writing down what you need yourself. My lib automacially generates code for inserting / deleting tuples into multi indexes such as (Map Int (Map Int PrimIdx)). $(let cds = defaultTable { tblName = cds , columns = [ (cdId, conT ''Int) , (title, conT ''Int) ] , primary = PrimaryUniq [ cdId ] [| 0 |] , indexes = [ Index title [] ] , tblStates = [ ( nextCdId, [t| Int |], [| 0 |] ) ] } tracks = let a=a -- updateNumRows n = [| \n - cdUpdateByPK (\r - r { num_tracks = (num_tracks r) + $(n) } ) |] in defaultTable { tblName = tracks , columns = [ (trackId, conT ''Int ) , (name, conT ''String) , (cd, conT ''Int) -- foreign key ] , primary = PrimaryUniq [ cd, trackId ] [| 0 |] , indexes = [ Index cd [ IndexUnique trackId ] ] --the id is uniq foreach cd -- checks = [ foreignConstraint cd cds id ] -- triggers = [ InsertUpdate (Just [cd]) [| cdUpdateByPK ( updateNum_tracks (+1) ) . pk |] -- DeleteUpdate (Just [cd]) [| cdUpdateByPK ( updateNum_tracks (-1) ) . pk |] -- ] } db = defaultDB { dbName = my , tables = [ cds, tracks] , statistics = True } in createDB db) If you're interested drop me a mail. Marc ___ 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] announcing darcs 2.1.0pre2
Hi everybody, The second pre-release of darcs 2.1 (formerly known as 2.0.3) is now available at http://darcs.net/darcs-2.1.0pre2.tar.gz We have increased the version number since the last pre-release because we are adopting an important new behaviour: The darcs initialize command now creates darcs-2 format repositories by default This will help new repositories to benefit from the improved handling of duplicate patches and to avoid the exponential time conflicts problem. Upcoming release schedule - 2008-10-03: darcs 2.1.0pre3 2008-10-10: darcs 2.1.0 Work remaining -- * http://bugs.darcs.net/issue971 (Petr Ročkai) When using hashed or repositories, allow darcs check to deal with filenames that differ only in case when run on a case-insensitive filesystem. Petr has done 90% of the work for this -- he has implemented this for darcs repair -- so this shall largely be a question of refactoring. * http://bugs.darcs.net/issue1003 Allow darcs-transfer mode to deal with a specific set of missing files (namely _darcs/format) so that users can benefit from ssh connection sharing even if the remote end uses an old-fashioned repository. In the meantime, a simple workaround is to touch the _darcs/format file in the remote repoistory * http://bugs.darcs.net/issue1078 Fix a corner case in paths handling that makes darcs overly cautious if the repository is a symbolic link * http://bugs.darcs.net/issue1026 Improve the error messages for 'bug in get_extra' errors, which can happen if darcs is fooled into thinking that two patches are the same. Changes since the last pre-release -- * User Experience: Do not allow users to add files to a darcs repository if their filenames would be considered invalid under Windows. This can be overridden with the --reserved-ok flag (issue53, Eric Kow) * Bug Fix: Do not leave behind a half-gotten directory if darcs get fails (issue1041, Vlad Dogaru, David Roundy) * User Experience: notice when you are trying to pull from a seemingly unrelated repository, that is one with a sufficiently different history. This can be overridden with the --allow-unrelated-repos flag (Dmitry Kurochkin, David Roundy) * Bug Fix: Fix hang after a user input error (for example, EOF) (Judah Jacobson) * Quality Assurance: Improvements to documentation and online help (Simon Michael) -- Eric Kow http://www.nltg.brighton.ac.uk/home/Eric.Kow PGP Key ID: 08AC04F9 pgpUwYX1m4b3t.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: pure Haskell database
jean-christophe mincke [EMAIL PROTECTED] wrote: What is this strange syntax columns = [ (trackId, conT *''Int* ) It looks like a not ended string literal unless I still have sth to learn about Haskell. ' isn't special in Haskell, it's idiomatic: you often see things like foo' = bar foo , as mathematicians and haskellers are to lazy to think of a new name for foo just because they got a derived foo. I, too, have no idea what *''Int* means. It's part of the just use the *%*$^!#!$%!^ operator problem. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
On Thu, Sep 25, 2008 at 11:52:26AM +0200, jean-christophe mincke wrote: Marc What is this strange syntax columns = [ (trackId, conT ''Int ) Hi J-C, I'ts part of template haskell and tells ghc to use the type referenced by Int. There are some getting started guides on haskell.org By the way you can enhance readability of your messages if you only keep that part of the message you're refering to. Sincerly Marc Weber ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] pure Haskell database
Hello jean-christophe, Thursday, September 25, 2008, 1:52:26 PM, you wrote: columns = [ (trackId, conT ''Int ) It looks like a not ended string literal unless I still have sth to learn about Haskell. it's TemplateHaskell, look for Reification in http://www.haskell.org/bz/thdoc.htm -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Android
2008/9/24 Galchin, Vasili [EMAIL PROTECTED]: Do there currently (or in the works) exist FFI bindings for Google's Android API? The Android API is obviously a Java API, additionally Android will only execute DEX bytecode programs, so you would first need a way to compile Haskell to Java, Java bytecode or DEX directly. A Google search for haskell java turns up at least one good candidate[1], but if you manage to get that working well, binding the APIs is a rather trivial task ;) [1] http://www.cse.unsw.edu.au/~pls/thesis-topics/ghcjava.html AGL -- Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Google Android
On 25 Sep 2008, at 13:33, Adam Langley wrote: A Google search for haskell java turns up at least one good candidate[1], but if you manage to get that working well, binding the APIs is a rather trivial task ;) [1] http://www.cse.unsw.edu.au/~pls/thesis-topics/ghcjava.html That's actually just a thesis proposal, not actual work done. Try this for something closer to realization: http://www.cs.rit.edu/~bja8464/lambdavm/ Regards, Maarten ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Where is OpenGL loadMatrix ?
Hi, I can't find the loadMatrix function in http://hackage.haskell.org/packages/archive/OpenGL/latest/doc/html/Graphics-Rendering-OpenGL-GL-CoordTrans.html Should I use loadIdentity then multMatrix instead ? Thank you, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Where is OpenGL loadMatrix ?
On Thu, Sep 25, 2008 at 15:39, minh thu [EMAIL PROTECTED] wrote: Hi, I can't find the loadMatrix function in http://hackage.haskell.org/packages/archive/OpenGL/latest/doc/html/Graphics-Rendering-OpenGL-GL-CoordTrans.html Should I use loadIdentity then multMatrix instead ? Thank you, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe From what I can see in the source, loadMatrix is method of class MatrixComponent [1]: instance MatrixComponent GLfloat_ where getMatrix = getFloatv loadMatrix = glLoadMatrixf loadTransposeMatrix = glLoadTransposeMatrixfARB multMatrix_ = glMultMatrixf multTransposeMatrix = glMultTransposeMatrixfARB rotate a (Vector3 x y z) = glRotatef a x y z translate (Vector3 x y z) = glTranslatef x y z scale = glScalef However, for some reason it is not exported: MatrixOrder(..), MatrixComponent(rotate,translate,scale), Matrix(..), Best regards Christopher Skrzętnicki [1]: http://hackage.haskell.org/packages/archive/OpenGL/latest/doc/html/src/Graphics-Rendering-OpenGL-GL-CoordTrans.html#MatrixComponent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Where is OpenGL loadMatrix ?
minh thu [EMAIL PROTECTED] wrote: I can't find the loadMatrix function in http://hackage.haskell.org/packages/archive/OpenGL/latest/doc/html/Graphics-Rendering-OpenGL-GL-CoordTrans.html Should I use loadIdentity then multMatrix instead ? You're supposed to use withMatrix and regard OpenGL not as an imperative language, but as a markup language coincidentally using do to specify (flattened) lists. I even read about some library managing display lists transparently for you, but I can't recall where. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Where is OpenGL loadMatrix ?
2008/9/25 Achim Schneider [EMAIL PROTECTED]: minh thu [EMAIL PROTECTED] wrote: I can't find the loadMatrix function in http://hackage.haskell.org/packages/archive/OpenGL/latest/doc/html/Graphics-Rendering-OpenGL-GL-CoordTrans.html Should I use loadIdentity then multMatrix instead ? You're supposed to use withMatrix and regard OpenGL not as an imperative language, but as a markup language coincidentally using do to specify (flattened) lists. I even read about some library managing display lists transparently for you, but I can't recall where. If you're right, it's weird there are things like loadIdentity, $=, ... and it is even weirder to not provide loadMatrix (which can be done with loadIdenity and multMatrix). Anyway, the bindings are not that much functionnal, even with things like withMatrix. Cheers Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] StateWriter: a monad-writing exercise
Hello haskell-cafe, In my application I have a complex state threaded through long computation chains, and I need a way to log all state changes (so that the evolving state can be animated/replayed somewhere else). Initially I tried combining State and Writer monads but this allows for the possibility to change the state, and forget to write a log entry, etc. So I decided to write a separate monad, StateWriter l s, that takes a state-modifying function, l-s-s (l is an ADT for all the allowable state transitions), an initial state s, and only allows s to change by appending 'l' log entries inside the monad. The net result is that I should have read-only access to the current state inside the monad, and all state transitions should be logged (by going through the one function, the log entries serve as witnesses to all state transitions). Anyway, here's my (very rough!) first stab at the problem. This is the first time I've tried writing a monad so any comments/critiques are much appreciated. Also, about the 'StateWriter' idea in general: am I just (poorly?) reimplementing something obvious? Is it unlikely to scale well on real-world problems? Is there some way to combine the existing State and Writer monads to avoid having to do this? If there's nothing seriously wrong here, I was thinking my next step would be to try changing the lists to monoids (like in the Writer monad), and then to try writing a transformer version of the whole thing. Cheers, - Anthony LODI {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-} newtype StateWriter l s a = StateWriter { _runSWriter :: (l - s - s) - [l] - s - (a, [l], s) } instance Monad (StateWriter l s) where return a = StateWriter $ \_ ls s - (a, ls, s) (StateWriter x) = f = StateWriter $ \fn ls s - let (v, ls', s') = x fn ls s in _runSWriter (f v) fn ls' s' class MonadStateWriter m l s | m - l s where put :: l - m () get :: m s instance MonadStateWriter (StateWriter l s) l s where put l = StateWriter $ \fn ls s - ((), ls ++ [l], fn l s) get = StateWriter $ \fn ls s - (s, ls, s) runSWriter :: StateWriter l s a - (l - s - s) - s - (a, [l], s) runSWriter sw fn = _runSWriter sw fn [] data Ops = Inc | Dec deriving (Show) test :: StateWriter Ops Int String test = do put Inc put Inc put Inc val - get let op = if val == 3 then Dec else Inc put op return done stateFn :: Ops - Int - Int stateFn Inc s = s + 1 stateFn Dec s = s - 1 runtest = runSWriter test stateFn 0 -- (done,[Inc,Inc,Inc,Dec],2) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] StateWriter: a monad-writing exercise
On Thu, 25 Sep 2008, Anthony LODI wrote: Hello haskell-cafe, In my application I have a complex state threaded through long computation chains, and I need a way to log all state changes (so that the evolving state can be animated/replayed somewhere else). Initially I tried combining State and Writer monads but this allows for the possibility to change the state, and forget to write a log entry, etc. Instead of rewriting from scratch, you can also define newtype StateWriter l s a = StateWriter (StateT s (Writer l) a) and then the monad instance is just about wrapping and unwrapping. Or you use {-# LANGUAGE GeneralizedNewtypeDeriving #-} and 'deriving Monad'. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Where is OpenGL loadMatrix ?
withMatrix doesn't seem to have anything to do with glLoadMatrix. You are right that you can do glLoadMatrix with loadIdentity and multMatrix. To directly load a matrix, use the function matrix (with a Nothing argument). This will internally call the loadMatrix function that Krzysztof mentioned (which is correctly not exported). Note that in addition to loading a matrix, the matrix function is also used for retrieving the current matrix. (glGetFloatv with argument GL_MODELVIEW_MATRIX and friends). On Thu, Sep 25, 2008 at 5:12 PM, minh thu [EMAIL PROTECTED] wrote: 2008/9/25 Achim Schneider [EMAIL PROTECTED]: minh thu [EMAIL PROTECTED] wrote: I can't find the loadMatrix function in http://hackage.haskell.org/packages/archive/OpenGL/latest/doc/html/Graphics-Rendering-OpenGL-GL-CoordTrans.html Should I use loadIdentity then multMatrix instead ? You're supposed to use withMatrix and regard OpenGL not as an imperative language, but as a markup language coincidentally using do to specify (flattened) lists. I even read about some library managing display lists transparently for you, but I can't recall where. If you're right, it's weird there are things like loadIdentity, $=, ... and it is even weirder to not provide loadMatrix (which can be done with loadIdenity and multMatrix). Anyway, the bindings are not that much functionnal, even with things like withMatrix. Cheers Thu ___ 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: Where is OpenGL loadMatrix ?
minh thu [EMAIL PROTECTED] wrote: Anyway, the bindings are not that much functionnal, even with things like withMatrix. http://thread.gmane.org/gmane.comp.lang.haskell.cafe/35444/focus=35713 Mind you: regarding 3d, I barely manage to code up camera movements. That is, I don't use it much at all. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Where is OpenGL loadMatrix ?
2008/9/25 Bit Connor [EMAIL PROTECTED]: withMatrix doesn't seem to have anything to do with glLoadMatrix. You are right that you can do glLoadMatrix with loadIdentity and multMatrix. To directly load a matrix, use the function matrix (with a Nothing argument). This will internally call the loadMatrix function that Krzysztof mentioned (which is correctly not exported). Note that in addition to loading a matrix, the matrix function is also used for retrieving the current matrix. (glGetFloatv with argument GL_MODELVIEW_MATRIX and friends). Ok, thank you, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
Rich Neswold ha scritto: On Wed, Sep 24, 2008 at 4:17 PM, Manlio Perillo [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: I need a simple, concurrent safe, database, written in Haskell. A database with the interface of Data.Map would be great, since what I need to to is atomically increment some integer values, and I would like to avoid to use SQLite. How about MVar (Map k Int)? or even Map k (MVar Int)? Yes, it is a solution; and I can run a thread that every N seconds writes the database to a file. But this works only if the database is used by only one process. Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Microsoft's Craig Mundie outlines the future of computing
http://news.cnet.com/8301-13953_3-10050826-80.html?part=rsssubj=newsta g=2547-1_3-0-5 We have to see a paradigm change in the way we write applications. He also said that software development hasn't graduated to become a formal engineering discipline. The resilience of systems is not up to the task, he said. We have to master the transition to a parallel programming environment, with highly distributed, concurrent systems. It's nascent at this point but it's required to achieve these capabilities. Sounds like Haskell will fit well in this future world. Notice: This e-mail message, together with any attachments, contains information of Merck Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] GHC 6.10, OS X, Fink and CPPFLAGS
While trying to test 6.10, I ran into the issue that a number of the libraries it wants are not installed by default, and are most conveniently added via Fink. This includes gmp, binutils, readline, etc. /sw/ is not in the default gcc path, of course, so the usual solution is to add -I/sw/include, -L/sw/lib, etc. to it via the CPPFLAGS and LDFLAGS environment variables, which are supported by most[1] autoconf-based packages. The help text for ghc's configure script does in fact suggest that this is the case, and it has some code meant to read it; broken code, as it happens. As it is, the script fails to propagate those variables to whatever is responsible for compiling the RTS, which fails with a missing gmp.h, bfd.h, and so on. All those files exist live quite happily in /sw/include, and would no doubt appreciate visiting makefiles. So my question is two-fold: Is the help file wrong? Is there some other way to do it? Or is this in fact a bug, and if so, will any of you volunteer to fix it for me? ^_^ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Climbing up the shootout...
John Van Enk [EMAIL PROTECTED] writes: I'm going to have to agree with David... even if you ignore the multi-threaded projects, why couldn't the C programs just implement very specific version of the third party library inside their code? Or they could just FFI to the Haskell libraries :-) -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Problem with existential quantification
Dear all, I've written a function with the following type: build :: Bifunctor s = (forall b. (s a b - b) - b) - Fix s a When I try to compile I get the following error: Illegal polymorphic or qualified type: forall b. (s a b - b) - b In the type signature for `build': build :: (Bifunctor s) = (forall b. (s a b - b) - b) - Fix s a What's happening? E.M. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
On Thu, Sep 25, 2008 at 11:09 AM, Manlio Perillo [EMAIL PROTECTED]wrote: Rich Neswold ha scritto: On Wed, Sep 24, 2008 at 4:17 PM, Manlio Perillo [EMAIL PROTECTED]mailto: [EMAIL PROTECTED] wrote: I need a simple, concurrent safe, database, written in Haskell. A database with the interface of Data.Map would be great, since what I need to to is atomically increment some integer values, and I would like to avoid to use SQLite. How about MVar (Map k Int)? or even Map k (MVar Int)? Yes, it is a solution; and I can run a thread that every N seconds writes the database to a file. But this works only if the database is used by only one process. Ah. When you said concurrent safe, I thought you meant within the application. You're looking for something like thishttp://hackage.haskell.org/cgi-bin/hackage-scripts/package/anydbm . -- Rich LOI: https://www.google.com/reader/shared/00900594587109808626 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Injecting Haskell into C
I have not been following the details, but would you consider writing up your example on the GHC user guide Wiki? http://haskell.org/haskellwiki/GHC/Using_the_FFI It's a very good way to share your experience with others. I got that example from Claude Heiland-Allen. Unless he has any objections, or would like to do it himself, I can put it on the wiki. Anatoly ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Climbing up the shootout...
Hello Ketil, Thursday, September 25, 2008, 8:57:05 PM, you wrote: John Van Enk [EMAIL PROTECTED] writes: I'm going to have to agree with David... even if you ignore the multi-threaded projects, why couldn't the C programs just implement very specific version of the third party library inside their code? Or they could just FFI to the Haskell libraries :-) there are lots of green thread libs for C, they are just not bundled with gcc -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Injecting Haskell into C
I have not been following the details, but would you consider writing up your example on the GHC user guide Wiki? http://haskell.org/haskellwiki/GHC/Using_the_FFI It's a very good way to share your experience with others. I got that example from Claude Heiland-Allen. Unless he has any objections, or would like to do it himself, I can put it on the wiki. actually, its already on there, http://haskell.org/haskellwiki/GHC/Using_the_FFI#Callbacks_into_Haskell_from_foreign_code Anatoly ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Building DLLs
Andrew Coppin wrote: OK, so a GHC question: Apparently at some point, GHC used to support DLLs. And then it stopped working. And then it may or may not have been brought back again... Does anybody know exactly what the status of this is? Is it currently working or broken? If it's working, what can and can't you use it for? And how do you work it? ;-) Since nobody seems inclined to offer any help on this one, I started digging around with Google. It appears that this used to work sometime around 6.4.x, and then for some reason it stopped working. The docs for 6.8.3 indicate that you can compile a Haskell program as a DLL instead of an EXE, but that's it. The GHC Developer Wiki promises that this feature will definitely be back in GHC 6.10. But then, the same page promises an RC by 19 Sep 2008. More digging and I discover various status pages that suggest that this functionallity isn't working in HEAD yet, and will probably actually end up in 6.10.2 or maybe 6.10.3. Looking at the surface, it appears as if not very much is currently going on with GHC. And then, by pure chance, I happened across a link that allows you to access the GHC developers' mailing list, and woo-boy, it looks pretty damned busy in there! o_O (I was most amused to discover that Don is currently assigned on a GHC ticket that was created in response to a comment that was made by me - over a year ago...) So the current state of affairs seems clear: shared libraries are not currently supported. That leaves me with two questions: - Is this likely to make it into the next official GHC release? - Why did it break in the first place? PS. Oh, and though there's no RC yet, it appears that there *are* several betas available already, so maybe I'll fire up a virtual machine to play with those anyway... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Microsoft's Craig Mundie outlines the future of computing
Lihn, Steve [EMAIL PROTECTED] wrote: Notice: This e-mail message, together with any attachments, contains information of Merck Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp Dohme or MSD and in Japan, as Banyu - direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. Just curious: What'd happen if I forward this message to alt.slack? -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] StateWriter: a monad-writing exercise
On Thu, Sep 25, 2008 at 10:34 AM, Henning Thielemann [EMAIL PROTECTED] wrote: Instead of rewriting from scratch, you can also define newtype StateWriter l s a = StateWriter (StateT s (Writer l) a) Thanks for the tip! I knew there must be a way to reuse some of the existing machinery. I'll post back after I try this out. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: pure Haskell database
Rich Neswold [EMAIL PROTECTED] wrote: On Thu, Sep 25, 2008 at 11:09 AM, Manlio Perillo [EMAIL PROTECTED]wrote: Rich Neswold ha scritto: On Wed, Sep 24, 2008 at 4:17 PM, Manlio Perillo [EMAIL PROTECTED]mailto: [EMAIL PROTECTED] wrote: I need a simple, concurrent safe, database, written in Haskell. A database with the interface of Data.Map would be great, since what I need to to is atomically increment some integer values, and I would like to avoid to use SQLite. How about MVar (Map k Int)? or even Map k (MVar Int)? Yes, it is a solution; and I can run a thread that every N seconds writes the database to a file. But this works only if the database is used by only one process. Ah. When you said concurrent safe, I thought you meant within the application. You're looking for something like thishttp://hackage.haskell.org/cgi-bin/hackage-scripts/package/anydbm . Or even HApps-State (http://happs.org/) for moar 0v3rk1ll, of which you can never ever have enough. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Microsoft's Craig Mundie outlines the future of computing
On Sep 25, 2008, at 13:50 , Achim Schneider wrote: Lihn, Steve [EMAIL PROTECTED] wrote: Notice: This e-mail message, together with any attachments, contains information of Merck Co., Inc. (One Merck Drive, Whitehouse Station, Just curious: What'd happen if I forward this message to alt.slack? Technically if there's anyone on haskell-cafe who was not specifically intended to be a recipient, they are in violation of the boilerplate. (This is why lawyers who mandate such boilerplate are stupid.) -- 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: pure Haskell database
Achim Schneider wrote: Rich Neswold [EMAIL PROTECTED] wrote: On Thu, Sep 25, 2008 at 11:09 AM, Manlio Perillo [EMAIL PROTECTED]wrote: ... But this works only if the database is used by only one process. Ah. When you said concurrent safe, I thought you meant within the application. You're looking for something like thishttp://hackage.haskell.org/cgi-bin/hackage-scripts/package/anydbm . Or even HApps-State (http://happs.org/) for moar 0v3rk1ll, of which you can never ever have enough. HAppS-State doesn't currently solve the problem of the database being used by more than one process (does it?) In the current stable version, it basically maintains its data in-memory and keeps a checkpointed transaction log. This can be used with a sharded approach where each process manages its own little chunk of the data, which can work well for certain data access patterns. But if you want each process to have access to a common database, HAppS-State currently only gives you the low-level building blocks for that. I understand that there are plans and prototypes and work being done on more sophisticated features, like multi-master replication, but I don't think anything like that is usable today. Depending on the application requirements, it might be simple enough to implement a custom data access layer over a set of happs shards to do things like retrieve individual values that aren't in the current process, or perhaps do a MapReduce-style operation over all processes. But there's nothing like that out of the box, yet. Anton ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Microsoft's Craig Mundie outlines the future of computing
Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: On Sep 25, 2008, at 13:50 , Achim Schneider wrote: Lihn, Steve [EMAIL PROTECTED] wrote: Notice: This e-mail message, together with any attachments, contains information of Merck Co., Inc. (One Merck Drive, Whitehouse Station, Just curious: What'd happen if I forward this message to alt.slack? Technically if there's anyone on haskell-cafe who was not specifically intended to be a recipient, they are in violation of the boilerplate. (This is why lawyers who mandate such boilerplate are stupid.) Well, you could interpret the Haskell cafe as an entity, thou this: http://permalink.gmane.org/gmane.comp.lang.haskell.cafe/45155 could prove problematic. Gmane doesn't delete. I'm just imagining what'd happen if Merck Co decided to sack Steve for leaking information about their stance on Haskell to the public. Think of Steve countersueing on the grounds that the boilerplate is legally effective and thus no harm is done. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Red-Blue Stack
Jamie Brandon wrote: Try writing data RBStack = RBS [RBSItem] [RBSItem] where the first list are all the same colour and the start of the second list is a different colour. The rest should follow naturally and you will get amortised O(1) push and pop (you occasionally have to juggle the lists). I am afraid, but this does not give constant amortized time. Let me reformulate the data type you have in mind as follows: data Stack2 r b = Empty | S [r] (Stack2 b r) deriving (Eq, Show) We're using the type system to distinguish between red (r) and blue (b) elements. The list [r] corresponds to your first list and means that the stack has red elements on top. The rest is a stack with blue elements on top. Using different types for red and blue is extremely cool :) because the compiler will complain about buggy code that deletes red elements instead of blue ones and the like. It already helped me to find a bug in my implementation below. All stack operations like push and pop will be performed on the red elements. We can switch between red and blue by making the list empty recolor :: Stack2 r b - Stack2 b r recolor (S [] t) = t recolor t= S [] t In other words, a stack with blue elements on top is a red stack with an empty list of red elements on top :). We impose the /invariant/ that only the topmost list may be empty. Pushing a red element onto the stack is straightforward. push :: r - Stack2 r b - Stack2 r b push r Empty= S [r] Empty push r (S rs t) = S (r:rs) t and so is pushing blue elements thanks to recoloring pushB :: b - Stack2 r b - Stack2 r b pushB b = recolor . push b . recolor The topmost element may be either blue or red top :: Stack2 r b - Maybe (Either r b) top Empty = Nothing top (S []t) = fmap (\(Left b) - Right b) (top t) top (S (r:_) t) = Just (Left r) Most importantly, we want to remove elements. Removing a red element is easy if there are red elements on the top pop :: Stack2 r b - Stack2 r b pop (S (_:rs) t ) = S rs t otherwise we will have to remove them from behind the blue elements while taking care that our /invariant/ still holds. pop (S [] (S bs t)) = S [] . s bs . pop $ t where -- s is like S but takes care of the invariant s bs (S [] Empty ) = S bs Empty s bs (S [] (S bs' t')) = S (bs ++ bs') t' s bs t = t pop _ = Empty Exercise: Find and correct the bug in this implementation of pop ! Hint: let the type checker tell you where it is. Quiz question: How to remove blue elements? Unfortunately, this whole implementation is not O(1) time. The problem is our use of ++. Consider the stack S [R] $ S [B] $ S [R] $ S [B] $ S [R] $ S [B] $ S [R] $ S [B] $ Empty Removing all the blue elements from this stack will give S ((([R] ++ [R]) ++ [R]) ++ [R]) Empty and we see the feared left-parenthesized application of list concatenation. Removing all red elements but one and asking for top will take quadratic time which doesn't amortize to O(1). In other words, while cool, the above implementation is not really what you want, Matthew. Quite a disappointing result for such a long e-mail ;). But don't worry, in a subsequent post, I'll turn the above ideas into a better solution and I'll also explain why implementing this data structure seems more difficult in Haskell than in Java. Regards, apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: pure Haskell database
Anton van Straaten [EMAIL PROTECTED] wrote: Achim Schneider wrote: Rich Neswold [EMAIL PROTECTED] wrote: On Thu, Sep 25, 2008 at 11:09 AM, Manlio Perillo [EMAIL PROTECTED]wrote: ... But this works only if the database is used by only one process. Ah. When you said concurrent safe, I thought you meant within the application. You're looking for something like thishttp://hackage.haskell.org/cgi-bin/hackage-scripts/package/anydbm . Or even HApps-State (http://happs.org/) for moar 0v3rk1ll, of which you can never ever have enough. HAppS-State doesn't currently solve the problem of the database being used by more than one process (does it?) In the current stable version, it basically maintains its data in-memory and keeps a checkpointed transaction log. After watching the BayFP presentation I assumed that they've got cross-master synchronising going, and that's nearly a year old news now. Merely synchronising processes is trivial if you can do that. If the HAppS documentation wasn't as lacking as it is or I'd have more time, I would know more about this. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
On Wed, Sep 24, 2008 at 5:17 PM, Manlio Perillo [EMAIL PROTECTED] wrote: Hi. I need a simple, concurrent safe, database, written in Haskell. A database with the interface of Data.Map would be great, since what I need to to is atomically increment some integer values, and I would like to avoid to use SQLite. If that's the entire requirement, and you're looking for something really fast, perhaps you could use a shared-memory region between the processes (your keys would map to addresses in shared memory), and use a compare-and-set algorithm to handle the atomic increments. If you're on Intel/Itanium, I believe there's a CMPXCHG instruction that will do atomic compare-and-set on a memory address, and I'm not sure you could get much faster than that. :-) Graham ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
And the one liner: (rand 1 10) = return . (\v - take v [1..10]) What about: take $ rand 1 10 * pure [1..10] (more readable IMHO). One could even define: f % x = f * pure x and have take $ rand 1 10 % [1..10] Also, why not using getRandomR(1,10) instead? take $ getRandomR (1,10) % [1..10] :: (MonadRandom m) = m Int That way you separate the generation from the IO. My getRandomR(0,3) % cents. -- Ariel J. Birnbaum ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] if - then - else layout
On Wed, 24 Sep 2008, leledumbo wrote: consider this partial program: if n5 then putStrLn big else putStrLn small this works fine in hugs, but in ghc I must change it to: if n5 then putStrLn big else putStrLn small maybe related http://www.haskell.org/haskellwiki/If-then-else ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problem with existential quantification
On Thu, Sep 25, 2008 at 1:15 PM, Eric [EMAIL PROTECTED] wrote: Dear all, I've written a function with the following type: build :: Bifunctor s = (forall b. (s a b - b) - b) - Fix s a When I try to compile I get the following error: Illegal polymorphic or qualified type: forall b. (s a b - b) - b In the type signature for `build': build :: (Bifunctor s) = (forall b. (s a b - b) - b) - Fix s a What's happening? That looks like it should work. I'm guessing you enabled ExistentialQuantification, but not Rank2Types or RankNTypes. The former allows you to use the forall keyword in data declarations, but you need one of the others to allow universal quantification in signatures, which is what build is using. This could be better documented. The GHC manual lists all the extensions it supports, but it doesn't use the same terminology as the Extension codes (e.g. arbitrary-rank polymorphism instead of RankNTypes), and there is a hierarchy of extensions that appears to be entirely implicit. For example, RankNTypes implies Rank2Types Rank2Types implies ExistentialQuantification Rank2Types implies PolymorphicComponents -- Dave Menendez [EMAIL PROTECTED] http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problem with existential quantification
On Thu, 25 Sep 2008, David Menendez wrote: That looks like it should work. I'm guessing you enabled ExistentialQuantification, but not Rank2Types or RankNTypes. The former allows you to use the forall keyword in data declarations, but you need one of the others to allow universal quantification in signatures, which is what build is using. This could be better documented. The GHC manual lists all the extensions it supports, but it doesn't use the same terminology as the Extension codes (e.g. arbitrary-rank polymorphism instead of RankNTypes), and there is a hierarchy of extensions that appears to be entirely implicit. For example, RankNTypes implies Rank2Types Rank2Types implies ExistentialQuantification Rank2Types implies PolymorphicComponents Something to add to http://www.haskell.org/haskellwiki/Rank-N_types ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
Graham Fawcett ha scritto: On Wed, Sep 24, 2008 at 5:17 PM, Manlio Perillo [EMAIL PROTECTED] wrote: Hi. I need a simple, concurrent safe, database, written in Haskell. A database with the interface of Data.Map would be great, since what I need to to is atomically increment some integer values, and I would like to avoid to use SQLite. If that's the entire requirement, and you're looking for something really fast, perhaps you could use a shared-memory region between the processes (your keys would map to addresses in shared memory), and use a compare-and-set algorithm to handle the atomic increments. If you're on Intel/Itanium, I believe there's a CMPXCHG instruction that will do atomic compare-and-set on a memory address, and I'm not sure you could get much faster than that. :-) I have an early draft of this type of database (written in D). Operations on integers use CMPXCHG, and for other operations a simple spin lock (implemented following the implementation in Nginx) is used. The problem is that it is a simple shared array! This means that you need to know in advance the data index in the array; for some type of applications this is true, I was trying to implement that database for using it in my HTTP Digest authentication implementation (http://hg.mperillo.ath.cx/wsgix/file/tip/wsgix/auth/auth_digest.py), in order to improve security, using not so restful support in the RFC 2617. Graham Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Red-Blue Stack
Matthew Eastman said: i.e. popping Blue in [Red, Red, Blue, Red, Blue] would give [Red, Red, Blue] Hmm, did you mean [Red,Blue] or [Red,Red,Red,Blue]? Judging by your implementation of remUseless, I'm guessing the latter. Here is a more straightforward approach than apfelmus'. I store colours separately, but count insertions so that I can easily reconstruct the overall ordering. To save myself some work, I've generalised to an arbitrary set of colours, though for O(1) behaviour, I'm assuming the set of colours is bounded finite. Unfortunately, this is still not quite O(1), due to the use of an Integer which can grow without bound. In practice, though, I don't think any of us will live long enough to notice. \begin{code} import qualified Data.Map as M import Data.List import Data.Maybe import Control.Arrow data CStack c a = CStack !Integer (M.Map c [(Integer,a)]) empty :: CStack c a empty = CStack 0 M.empty push :: Ord c = c - a - CStack c a - CStack c a push c x (CStack i m) = CStack (i+1) (M.insertWith (++) c [(i,x)] m) popc :: Ord c = c - CStack c a - Maybe (a, CStack c a) popc c (CStack i m) = do cs - M.lookup c m (_,x) - listToMaybe cs return (x, CStack i (M.adjust tail c m)) pop :: Ord c = CStack c a - Maybe ((c,a), CStack c a) pop = undefined -- left as an exercise :-) toList :: CStack c a - [(c,a)] toList (CStack _ m) = map snd (foldr merge [] (map dist (M.toList m))) where dist (c,xs) = map (second ((,) c)) xs merge (xxs@((i,x):xs)) (yys@((j,y):ys)) | i j = (i,x) : merge xs yys | i j = (j,y) : merge xxs ys merge xs [] = xs merge [] ys = ys instance (Eq a, Eq c) = Eq (CStack c a) where x == y = toList x == toList y instance (Show a, Show c) = Show (CStack c a) where show = show . toList data RBColour = Red | Blue deriving (Eq,Ord,Show) type RedBlueStack a = CStack RBColour a \end{code} ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] pure Haskell database
On Thu, Sep 25, 2008 at 5:09 PM, Manlio Perillo [EMAIL PROTECTED] wrote: Graham Fawcett ha scritto: If you're on Intel/Itanium, I believe there's a CMPXCHG instruction that will do atomic compare-and-set on a memory address, and I'm not sure you could get much faster than that. :-) I have an early draft of this type of database (written in D). Operations on integers use CMPXCHG, and for other operations a simple spin lock (implemented following the implementation in Nginx) is used. And I thought I was being original. :-) The problem is that it is a simple shared array! I'm guessing you've also ruled out sparse arrays? If not, what complexity is acceptable on your lookup function? Graham (sorry if this heading off-topic for the list.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Red-Blue Stack
I am afraid, but this does not give constant amortized time. sendEmail :: ProperlyThoughtOut Idea - IO () Clearly my brain lacks a type checker. Jamie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Random question
Iain Barnett wrote: On 24 Sep 2008, at 10:13 pm, Evan Laforge wrote: For one approach, check out 'replicate' to make copies of something, and then 'sequence' to run them and return a list. Thanks, I haven't found anything that explains 'sequence' well yet, but I'll keep looking. Yet another explanation that might be helpful... Consider a functor as a container (hence an |F a| value is an F-shaped container of values of type |a|). And remember that every monad is also a functor. We could imagine a value of type |F (G a)|, that is, a big F-shaped box containing many G-shaped boxes each containing a's. When G is a monad and not just a plain old functor, values of this sort are rather irksome to deal with because of the side effects. But, if the functor F has certain properties[1] then it is possible to have a function that takes an |F (G a)| and distributes F over G to yield an analogous |G (F a)| value that preserves the internal structures of F and G. This function essentially runs a string through all the little |G a| beads in order to run them in some canonical sequence[2], it then collects their results and wraps them up in F-shaped boxes. One of the places such a function is helpful is this. Consider if you have an |F a| value and you then fmap a monadic function |a - G b| over it. You now have an |F (G b)| but no simple way to get back what you really want: an |F b| value. If you have a function to distribute the functors then you can get a |G (F b)| which is a program that computes an |F b| subject to the state in G which it threads through each of those calls to that monadic function we fmapped over the |F a|. The |sequence| function from the Prelude is exactly such a function, except that it fixes F to be [ ] and is only polymorphic over G and a. We could in principle have a more general function that doesn't force you to use lists. In fact, it exists as Data.Traversable.sequenceA which allows F to be any Data.Traversable structure and allows G to be any applicative functor (which are halfway between functors and monads). [1] Namely being Data.Foldable and Data.Traversable so that we can, respectively, consume and reconstruct F containers. It's these mathematical properties we need, not the type classes themselves. Alternatively, if we can define for |f| a function |fsequence :: (Monad m) = f (m a) - m (f a)| then we can use that function to define instances for both of those type classes; this is what Data.Traversable's fmapDefault and foldMapDefault functions are about. [2] What sequence this threading occurs in matches whatever order the folding function iterates over the elements in the F functor. -- Live well, ~wren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Red-Blue Stack
On Thu, 2008-09-25 at 00:11 -0400, Matthew Eastman wrote: Hey guys, This is probably more of a question about functional programming than it is about Haskell, but hopefully you can help me out. I'm new to thinking about things in a functional way so I'm not sure what the best way to do some things are. I'm in a data structures course right now, and the assignments for the course are done in Java. I figured it'd be fun to try and implement them in Haskell as well. The part of the assignment I'm working on is to implement a RedBlueStack, a stack where you can push items in as either Red or Blue. You can pop Red and Blue items individually, but the stack has to keep track of the overall order of items. i.e. popping Blue in [Red, Red, Blue, Red, Blue] would give [Red, Red, Blue] All push and pop operations on the stack have to be done in O(1) time. It was easy to do in Java since you can just keep track of everything with a few pointers, but it took a while to get the Haskell version working. Maybe I'm just not used to the functional way of doing things. Note that purely functional data structures are inherently persistent (i.e. you can access old copies as well as new copies.) This is a significant extra constraint. Your Java type is almost certainly ephemeral, the opposite of persistent. Rewriting your Java code to be persistent while still maintaining the asymptotic complexities of the relevant operations is non-trivial. You can always achieve persistence by (deep) copying, but copying is an O(n) operation at best. Consider a simple example. The requirements are a sequence of elements with O(1) add and remove to beginning and end. This is easy. One solution is a doubly-linked list with head and tail pointers. Now if I add the requirement that it is persistent, i.e. if I have list1 = [a,b,c,d] and I make list2 = list1.RemoveLast(), list1 should still be [a,b,c,d] and list2 should be [a,b,c]. Now the problem is quite a bit more difficult. Try it. Also try to prove (informally or formally) that the asymptotic complexities hold and that the persistence guarantee holds. Okasaki's thesis and/or book, Purely Functional Data Structures goes into the differences and how to produce data structures with good complexity characteristics in a purely functional language. The implementations described are rather different from the usual implementations used for ephemeral data structures. The real-time deques described in the thesis are one solution to the above problem, in this case a purely functional one. In a nutshell, persistent data structures are inherently more difficult to build than ephemeral ones*, which are what are usually described, and in a purely functional language all data structures are persistent. * Proof: If I have a persistent data structure I can make an ephemeral one with the same asymptotic complexity behaviour by simply having a mutable reference holding the persistent data structure. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: datapacker 1.0.1
Hi everyone, I'm finding Haskell to be a really handy language for writing programs designed to be used from shell scripts of late. hpodder, twidge, and datapacker are al on Hackage. I released dataacker 1.0.1 recently. It's about one fifth the size of a close competitor written in another language. And it has more useful features, IMHO ;-) http://changelog.complete.org/posts/760-New-version-of-datapacker.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Random question
Ariel J. Birnbaum [EMAIL PROTECTED] wrote: And the one liner: (rand 1 10) = return . (\v - take v [1..10]) What about: take $ rand 1 10 * pure [1..10] The reason why this doesn't work by default is the occurrence distribution of tutorials about warm, fuzzy things and warm, funky things. -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or broadcasting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: datapacker 1.0.1
jgoerzen: Hi everyone, I'm finding Haskell to be a really handy language for writing programs designed to be used from shell scripts of late. hpodder, twidge, and datapacker are al on Hackage. I released dataacker 1.0.1 recently. It's about one fifth the size of a close competitor written in another language. And it has more useful features, IMHO ;-) http://changelog.complete.org/posts/760-New-version-of-datapacker.html Woo. Packaged natively for Arch, http://aur.archlinux.org/packages.php?ID=17824 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe