[Haskell-cafe] How to give unique name/id to nodes outside any monad ?
Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Template Haskell question
Good tricks! Would one of you like to write them up on the Wiki? http://haskell.org/haskellwiki/Template_Haskell Simon | -Original Message- | From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of | Ryan Ingram | Sent: 08 January 2009 01:55 | To: Jeff Heard | Cc: haskell | Subject: Re: [Haskell-cafe] Template Haskell question | | On Wed, Jan 7, 2009 at 12:58 PM, Jeff Heard jefferson.r.he...@gmail.com wrote: | And how do I encode | | a{ mousePositionf = b } | | in template haskell without using the [| |] syntax, so that I can use mkName? | | Whenever I have a question like that, I just ask ghci: | | $ ghci -fth | ghci :m Control.Monad.Identity Language.Haskell.TH | ghci runQ [| 1 + 1 |] | InfixE (Just (LitE (IntegerL 1))) (VarE GHC.Num.+) (Just (LitE (IntegerL 1))) | ghci runQ [| \x - x { runIdentity = 1 } |] | LamE [VarP x_1] (RecUpdE (VarE x_1) [(Control.Monad.Identity.runIdentity,LitE (I | ntegerL 1))]) | | Note that GHCi shows TH names without mkName or quotes, so you need | to add those. But it shows you the structure you want to generate. | | You can also use $() and [| |] inside [| |] to generate additional | data in TH directly: | | ghci runQ $ do { VarE n - [| runIdentity |] ; [| \x - $(recUpdE [| | x |] [ fmap (\e - (n,e)) [| 1 |] ]) |] } | LamE [VarP x_2] (RecUpdE (VarE x_2) [(Control.Monad.Identity.runIdentity,LitE (I | ntegerL 1))]) | | Note the VarE n - [| identifier |] trick to extract the name from | an identifier. | | -- ryan | ___ | 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] How to give unique name/id to nodes outside any monad ?
On Thu, Jan 8, 2009 at 1:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? If your graphs are acyclic, then you can label each node with a hash and use that for comparison. This usually works very well in practice. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to give unique name/id to nodes outside any monad ?
Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, 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
Re: [Haskell-cafe] How to give unique name/id to nodes outside any monad ?
2009/1/8 Luke Palmer lrpal...@gmail.com: On Thu, Jan 8, 2009 at 1:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? If your graphs are acyclic, then you can label each node with a hash and use that for comparison. This usually works very well in practice. Precisely ! How do you give that label to each node; i.e. how to ensure they are unique ? I don't want to end up with do c - newNodeC a - newNodeA [c] b - newNodeB a a where newNodeX hides the handling of label. I'd like to simply write, like above, b = B a a where a = A [C] or, maybe, b = B label a a where a = A label [C] The question is : how can label be different each time ? Thanks, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to give unique name/id to nodes outside any monad ?
Well, the processing of the data structure has to be done in the IO monad. What is the library you talk about ? Could it give the stable names (in IO) for each node of the mentioned graph (I mean, after the graph has been constructed purely) ? Thanks, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, 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
Re: [Haskell-cafe] How to give unique name/id to nodes outside any monad ?
Great, System.Mem.StableName [1] seems to be able to do the trick. Thank you. [1] http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-StableName.html 2009/1/8 minh thu not...@gmail.com: Well, the processing of the data structure has to be done in the IO monad. What is the library you talk about ? Could it give the stable names (in IO) for each node of the mentioned graph (I mean, after the graph has been constructed purely) ? Thanks, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, 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
Re: [Haskell-cafe] How to give unique name/id to nodes outside any monad ?
On Thu, Jan 8, 2009 at 1:49 AM, minh thu not...@gmail.com wrote: I'd like to simply write, like above, b = B a a where a = A [C] or, maybe, b = B label a a where a = A label [C] The question is : how can label be different each time ? Haskell is pure, so I can answer this precisely: obviously you cannot. Sharing is *not* observable in Haskell, because it breaks referential transparency, a very important property. So what I meant by hashing was, eg.: newtype Hash = ... data Foo = Foo Hash Int [Foo] mkFoo :: Int - [Foo] - Foo mkFoo n xs = Foo (hash (show n ++ concatMap (\(Foo h _ _) - show h))) n xs hash :: String - Hash hash = ... -- some cryptographic hash function Probably going through Strings is not the smartest way, but you get the idea? Then when two Foos have the same hash, you have odds of 1/2^64 or whatever that they are the same object. You could also compare directly without hashes, but that is slower for large data structures (more correct though -- hash comparisons always gave me the creeps). I just saw your reply to the StableName suggestion. I should warn you -- you should use this information only for optimization internal to your program. If you use it for observable effects, e.g. generating code or writing to a file[1], you are writing *bad haskell*, and you will not only lose the benefits of Haskell's purity, but you will be bitten by the unpredictable zeal of the optimizer. Luke [1] Unless you read the file back into the data structure, where the sharing is once again not observable. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to give unique name/id to nodes outside any monad ?
Nothing, simply the notation. Now, with the remark of Luke, I'm wondering how bad it is to use makeStableName/hashStableName to copy the data structure in a similar one with explicit reference (that is, using pointer or keys in a map or whatever). Thank you, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Look at http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-StableName.html. But what's wrong with constructing the graph in a monad? On Thu, Jan 8, 2009 at 9:53 AM, minh thu not...@gmail.com wrote: Well, the processing of the data structure has to be done in the IO monad. What is the library you talk about ? Could it give the stable names (in IO) for each node of the mentioned graph (I mean, after the graph has been constructed purely) ? Thanks, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, 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] Debugging STM
Hi, Does anyone have any advice on how to inspect complex TVar data structures that may include cycles? They're opaque as far as Show goes. And sometimes I'd like a more comprehensive view of my data structures at the ghci prompt rather than the dribs and drabs I get by typing x - atomically $ readTVar var and the like all the time. Also, do TVars have a printable identity for debugging purposes? Thanks -John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hypothetical Haskell job in New York
Tony Hannan ha scritto: Let me give you more information about this hypothetical job posting. Our company is a startup CDN (http://en.wikipedia.org/wiki/Content_Delivery_Network) about 3 years old and doing well. You would hythothetically be one of 7 programmer who write all the software involved in a CDN including http server, dns server, monitoring, load balancing, customer and operator user interface, etc. The pay depends on experience but is good. Isn't it better to use Erlang for the http and dns server ? I don't really like the syntax, but you have many things already implemented. Unfortunately Haskell is not yet ready for this task. http://eddie.sourceforge.net/what.html http://yaws.hyber.org/ [...] Regards Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Computer time, independent of date
Hi, I'm writing a program where I need to know elapsed times between some events, but I can't depende on Data.Time since ntpd or user can change that while my program is running. Is there an alternative? Something like how much time has passed since the program has started would be great. Thanks, MaurĂcio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
Manlio Perillo manlio_peri...@libero.it wrote: Unfortunately Haskell is not yet ready for this task. Could you -- or someone else -- please elaborate on this? I've heard it once in the context of a webbrowser, the reason given was that ghc doesn't deallocate memory, that is, the gc heap only increases. I doubt it'd be hard to fix, not to mention that, iff a Haskell process is more or less the only process running on a system, deallocation becomes practically irrelevant... which'd be the case with e.g. a HAppS production server. Any other known problems? -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ideas for a phd in the area of paralleism?
Hi, check http://www.intellasys.net/index.php?option=com_contenttask=viewid=35 http://groups.google.com.tw/group/seaforth That's a FORTH cpu I ever took a look one year ago when my professor introduced it. It has some very promising features as the above links claims.The most impressive one for me is its mechanism of inter-core commuication. Unfortunately(FORTH advocators may disagree), it seems to require native FORTH programming and manual parallelism among the processor arrary. I wonder whether it's possible to implement a compiler with parallelism capability(coordinate those cores) on it, especially for functional languages. Regards, Mura ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
Achim Schneider ha scritto: Manlio Perillo manlio_peri...@libero.it wrote: Unfortunately Haskell is not yet ready for this task. Could you -- or someone else -- please elaborate on this? Here is a list of things that I would like to see in GHC to start developing a server application (in order of importance) 1) Support for scalable IO multiplexing. The GHC runtime only supports select. I find the ideas from the Unify paper interesting, however I don't really know if the implementation is robust. I would also like to have epoll/kqueue support in single threaded applications 2) Convenient and flexible method for reading a stream of data. Lazy IO is not the answer. Iteratee seems interesting. 3) Support for process supervisor in the runtime. Of course I'm not interested in the Erlang supervisor system (spread over multiple machine), but I would like a simple master/slave system, like Nginx [...] Regards Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Computer time, independent of date
Is there an alternative? Something like how much time has passed since the program has started would be great. Have a look at benchpress on hackage. Sincerly Marc Weber ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How to give unique name/id to nodes outside any monad ?
minh thu not...@gmail.com wrote: Nothing, simply the notation. Now, with the remark of Luke, I'm wondering how bad it is to use makeStableName/hashStableName to copy the data structure in a similar one with explicit reference (that is, using pointer or keys in a map or whatever). Probably you're misusing the notation. I don't see any reason, why monadic notation should be less readable. Usually it's even more readable. Luke's remark is very valid. Haskell is the wrong language for imperative programming. You don't have _any_ benefit of Haskell, if you use it like C. Try to change your mind. Monads aren't evil. They are there to make your life easier. Way easier than imperative methods. Greets, Ertugrul. Thank you, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Look at http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-StableName.html. But what's wrong with constructing the graph in a monad? On Thu, Jan 8, 2009 at 9:53 AM, minh thu not...@gmail.com wrote: Well, the processing of the data structure has to be done in the IO monad. What is the library you talk about ? Could it give the stable names (in IO) for each node of the mentioned graph (I mean, after the graph has been constructed purely) ? Thanks, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- nightmare = unsafePerformIO (getWrongWife = sex) http://blog.ertes.de/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Computer time, independent of date
Is there an alternative? Something like how much time has passed since the program has started would be great. Have a look at benchpress on hackage. But benchpress uses Data.Time.Clock.getCurrentTime. I understand that is dependent from configuration. It's okay to benchmark a fast application, but mine will be running for days, so it would not be reliable. Best, MaurĂcio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: How to give unique name/id to nodes outside any monad ?
2009/1/8 Ertugrul Soeylemez e...@ertes.de: minh thu not...@gmail.com wrote: Nothing, simply the notation. Now, with the remark of Luke, I'm wondering how bad it is to use makeStableName/hashStableName to copy the data structure in a similar one with explicit reference (that is, using pointer or keys in a map or whatever). Probably you're misusing the notation. I don't see any reason, why monadic notation should be less readable. Usually it's even more readable. Luke's remark is very valid. Haskell is the wrong language for imperative programming. You don't have _any_ benefit of Haskell, if you use it like C. Try to change your mind. Monads aren't evil. They are there to make your life easier. Way easier than imperative methods. Well, maybe it's is just my opinion, but I found the non-monadic code in the previous mail easier to write than the monadic one... I don't know against what you're making the compareason to say it's more readable. Although I agree using Haskell requires some change of thinking, statement like yours are a bit too much for me. I find Haskell a nice language even for imperative programming... Cheers, Thu Greets, Ertugrul. Thank you, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Look at http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-StableName.html. But what's wrong with constructing the graph in a monad? On Thu, Jan 8, 2009 at 9:53 AM, minh thu not...@gmail.com wrote: Well, the processing of the data structure has to be done in the IO monad. What is the library you talk about ? Could it give the stable names (in IO) for each node of the mentioned graph (I mean, after the graph has been constructed purely) ? Thanks, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- nightmare = unsafePerformIO (getWrongWife = sex) http://blog.ertes.de/ ___ 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] State Monad - using the updated state
Ryan gave some great advice about restructuring your program to do what you want, but I wanted to give a small explanation of why that's necessary. 2009/1/7 Phil pbeadl...@mail2web.com: I want to be able to do: Get_a_random_number a whole load of other stuff Get the next number as defined by the updated state in the first call some more stuff Get another number, and so on. The issue you're having is that you're trying to do the other stuff in your 'main', but main isn't inside the State monad. The only State computation you're calling from main is getRanq1, but you really need another State computation that does other stuff and calls getRanq1 itself. That's what Ryan's first suggestion implements. You need all your other stuff to be done inside the State monad so that it has read/update access to the current random state. So all your main does is run a State computation. That computation calls getRanq1 itself and then other stuff in between calls to getRanq1. Does that make sense? Kurt ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On 2009-01-08 12:10, Achim Schneider wrote: Manlio Perillomanlio_peri...@libero.it wrote: Unfortunately Haskell is not yet ready for this task. Could you -- or someone else -- please elaborate on this? I think Haskell is ready for a lot more than most people think. How about an operating system in Haskell, for example? I think House shows that it could be done. http://programatica.cs.pdx.edu/House/ I've heard it once in the context of a webbrowser, the reason given was that ghc doesn't deallocate memory, that is, the gc heap only increases. I doubt it'd be hard to fix, Even if the GHC RTS doesn't return unused heap memory to the operating system, I don't see why this would prevent you from implementing a useful web browser in Haskell. As a comparison, my Firefox process currently uses 717MB of memory. I usually restart Firefox every day to bring the memory use down to a reasonable level. The situation would probably be the same if I used a browser implemented in Haskell. Incidentally, I did implement a web browser in Haskell back in the 90s, and it worked fine :-) But that was before JavaScript and CSS, so it would take some work to make it useful on the web of today... http://www.cs.chalmers.se/~hallgren/wwwbrowser.html Thomas Hallgren ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
Haskell's networking support is very rudimentary. Erlang's is quite sophisticated. For network intensive applications, especially those requiring messaging, fault-tolerance, distribution, and so forth, there's no doubt that Erlang is a more productive choice. Not because of the language, per se, but because of all the stuff that is packaged with it, or available for it. Regards, John On Jan 8, 2009, at 4:10 AM, Achim Schneider wrote: Manlio Perillo manlio_peri...@libero.it wrote: Unfortunately Haskell is not yet ready for this task. Could you -- or someone else -- please elaborate on this? I've heard it once in the context of a webbrowser, the reason given was that ghc doesn't deallocate memory, that is, the gc heap only increases. I doubt it'd be hard to fix, not to mention that, iff a Haskell process is more or less the only process running on a system, deallocation becomes practically irrelevant... which'd be the case with e.g. a HAppS production server. Any other known problems? -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Taking Exception to Exceptions
On Thu, Jan 8, 2009 at 12:32 AM, Austin Seipp mad@gmail.com wrote: Excerpts from Immanuel Litzroth's message of Wed Jan 07 16:53:30 -0600 2009: ... I am little amazed that I cannot get catch, try or mapException to work without telling them which exceptions I want to catch. What is the rationale behind this? The rational is that it's normally not a good idea to simply gobble all exceptions; although the library makes it possible to do this anyway. I'd advice always putting an additional generic catch-all at the top level, at least to present the user a (possibly generic) error message, just to stay in control. This avoids the possibility of having an unwanted/unknown behavior from the run-time stack (for example, having the web server returning a generic 500 Internal Server error report, filled with every sort of goods a cracker would be happy for). Cristiano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Blitting one IOUArray into another
On 01/07/2009 14:36 , Neal Alexander wqeqwe...@hotmail.com wrote: Bueno, Denis wrote: Oh, do you mean by actually calling memcpy via ffi? http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Marshal-Uti ls.html Ah, thanks. Is there a way to simply cast an IOUArray Int Int64 into something like a Ptr Int64, or will I need to change my code to allocate the arrays differently (using something in Foreign.*)? I hoogle'd functions IOUArray a b - Ptr b, but couldn't find anything. Denis ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Computer time, independent of date
Mauricio wrote: But benchpress uses Data.Time.Clock.getCurrentTime. I understand that is dependent from configuration. It's okay to benchmark a fast application, but mine will be running for days, so it would not be reliable. benchpress also uses System.CPUTime -- is that what you are looking for? Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Taking Exception to Exceptions
I recommend this paper for info, it's very easy to follow: http://www.haskell.org/~simonmar/papers/ext-exceptions.pdfhttp://www.haskell.org/%7Esimonmar/papers/ext-exceptions.pdf Austin That paper cleared up most of my issues and it is amazing that it is not amongst the papers that are referenced at the top of the the page describing Control.Exception. Anyway, there is one more problem I have related to exceptions that is about forcing strictness. It relates to option parsing. I have an option -t that says which track from a file of tracks to print. So I go data Flags = TrackNumber !Int deriving(Read, Show, Eq) makeTrackNumber :: String - Flags makeTrackNumber str = TrackNumber $ read str options = [GetOpt.Option ['t'] [tracknumber] (GetOpt.ReqArg makeTrackNumber tracknumber) number of track to show] Now my main goes main = do args - getArgs opts - evaluate $ GetOpt.getOpt GetOpt.RequireOrder options args print done getting the opts case opts of ... which of course first prints done getting opts and then throws an exception if I give it a flag -t abc. What would be the way to proceed here? Do I increase the strictness or do I write a handler around my complete main? Even if I map the exception in makeTrackNumber to my very own exception how do I find out which exact call gave a problem i.e. which is the call stack at the moment the exception was thrown -- I might use makeTrackNumber in other contexts too. Thanks in advance, Immanuel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 8, 2009 at 8:32 AM, John A. De Goes j...@n-brain.net wrote: Haskell's networking support is very rudimentary. Erlang's is quite sophisticated. For network intensive applications, especially those requiring messaging, fault-tolerance, distribution, and so forth, there's no doubt that Erlang is a more productive choice. Not because of the language, per se, but because of all the stuff that is packaged with it, or available for it. Now I understand that there aren't(?) any Haskell implementations that can act as distributed nodes the way the Erlang implementation can, but I'm not familiar enough with Erlang to understand what it has for networking that the Haskell network packages don't have. Could you explain a bit further? I've been thinking a lot about network programming anyway lately am looking for library opportunities. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
Take, for example, RabbitMQ. There's nothing even remotely close in Haskell-land. RabbitMQ is written in 100% Erlang. It's built on Open Telecom Platform, which again is without equal in Haskell. There are a lot of theoretical reasons why Haskell would be a good choice to build libraries such as these, but lacking any production implementations, it's all just theory. Regards, John On Jan 8, 2009, at 8:41 AM, Creighton Hogg wrote: On Thu, Jan 8, 2009 at 8:32 AM, John A. De Goes j...@n-brain.net wrote: Haskell's networking support is very rudimentary. Erlang's is quite sophisticated. For network intensive applications, especially those requiring messaging, fault-tolerance, distribution, and so forth, there's no doubt that Erlang is a more productive choice. Not because of the language, per se, but because of all the stuff that is packaged with it, or available for it. Now I understand that there aren't(?) any Haskell implementations that can act as distributed nodes the way the Erlang implementation can, but I'm not familiar enough with Erlang to understand what it has for networking that the Haskell network packages don't have. Could you explain a bit further? I've been thinking a lot about network programming anyway lately am looking for library opportunities. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hypothetical Haskell job in New York
On Thu, Jan 8, 2009 at 11:58 AM, Manlio Perillo manlio_peri...@libero.it wrote: Unfortunately Haskell is not yet ready for this task. What makes you say that ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Defining methods generically for a class
I have the following class: class Region a where numDimensions :: a - Int dim :: Int - a - (Double,Double) merge :: a - a - a and several ancillary methods defined, the most importance of which is: bounds :: Region a = a - [(Double,Double)] bounds r = take (numDimensions r) . map dim . iterate (+1) $ 0 Let's say that I want all Regions to also be of class Eq, where regiona == regionb = all $ zipWith (==) (bounds regiona) (bounds regionb) How do I declare all Regions to be Eqs without putting it in the class body (since I define a function over all Regions that is independent of datatype that is an instance of Region)? Is it merely: instance Region a = Eq a where regiona == regionb = all $ zipWith (==) (bounds regiona) (bounds regionb) -- Jeff ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Defining methods generically for a class
On Thu, Jan 8, 2009 at 6:04 PM, Jeff Heard jefferson.r.he...@gmail.com wrote: ... How do I declare all Regions to be Eqs without putting it in the class body (since I define a function over all Regions that is independent of datatype that is an instance of Region)? Would this be a solution? class Eq a = Region a where ... Cristiano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Defining methods generically for a class
Hi Jeff, Jeff Heard wrote: instance Region a = Eq a where regiona == regionb = all $ zipWith (==) (bounds regiona) (bounds regionb) If you want to be Haskell98 compliant, why not define regionEquals :: Region a = a - a - Bool as above and use that everywhere instead of (==)? If you insist on using the overloaded (==), then in Haskell98 you will need to define individual Eq instances for all your custom region types. However, you can simply define (==) = regionEquals for all those types. Hope this helps, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Fwd: [Haskell-cafe] Defining methods generically for a class
-- Forwarded message -- From: Jeff Heard jefferson.r.he...@gmail.com Date: Thu, Jan 8, 2009 at 12:26 PM Subject: Re: [Haskell-cafe] Defining methods generically for a class To: Cristiano Paris fr...@theshire.org Not really... I'm not testing if each of the items a are equal, but rather that in the context of them being a Region, they are equal.As long dim (which is in the class) can be defined, then equality is defined over all types Region. On Thu, Jan 8, 2009 at 12:16 PM, Cristiano Paris fr...@theshire.org wrote: On Thu, Jan 8, 2009 at 6:04 PM, Jeff Heard jefferson.r.he...@gmail.com wrote: ... How do I declare all Regions to be Eqs without putting it in the class body (since I define a function over all Regions that is independent of datatype that is an instance of Region)? Would this be a solution? class Eq a = Region a where ... Cristiano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Defining methods generically for a class
That's probably the best thing to do, yes. The purpose of doing so was for Data.List.delete, but I see now there's a Data.List.deleteBy, so I can use the regionEquals function as my equality predicate. On Thu, Jan 8, 2009 at 12:26 PM, Martijn van Steenbergen mart...@van.steenbergen.nl wrote: Hi Jeff, Jeff Heard wrote: instance Region a = Eq a where regiona == regionb = all $ zipWith (==) (bounds regiona) (bounds regionb) If you want to be Haskell98 compliant, why not define regionEquals :: Region a = a - a - Bool as above and use that everywhere instead of (==)? If you insist on using the overloaded (==), then in Haskell98 you will need to define individual Eq instances for all your custom region types. However, you can simply define (==) = regionEquals for all those types. Hope this helps, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
Take, for example, RabbitMQ. There's nothing even remotely close in Haskell-land. That would be useful for systems that require an enterprise messaging system, I agree, but I don't see how that would be terribly important for a web server or most other networking services I might want to implement. John Tim Newsham http://www.thenewsh.com/~newsham/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
The number of applications requiring the implementation of a custom web server is an insignificant fraction of the number of applications requiring a messaging system. I don't think anyone would dispute Haskell's ability to do low-level, raw networking, of the type that few people actually need to do. It's the higher level stuff where there's a huge amount of room for improvement. Regards, John On Jan 8, 2009, at 10:31 AM, Tim Newsham wrote: That would be useful for systems that require an enterprise messaging system, I agree, but I don't see how that would be terribly important for a web server or most other networking services I might want to implement. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Taking Exception to Exceptions
On Thu, Jan 8, 2009 at 6:36 AM, Cristiano Paris fr...@theshire.org wrote: This avoids the possibility of having an unwanted/unknown behavior from the run-time stack (for example, having the web server returning a generic 500 Internal Server error report, filled with every sort of goods a cracker would be happy for). So the information should be written to the log rather than the browser, at least in production, but there's no reason not to catch the exception. Cristiano --Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hypothetical Haskell job in New York
manlio_perillo: Tony Hannan ha scritto: Let me give you more information about this hypothetical job posting. Our company is a startup CDN (http://en.wikipedia.org/wiki/Content_Delivery_Network) about 3 years old and doing well. You would hythothetically be one of 7 programmer who write all the software involved in a CDN including http server, dns server, monitoring, load balancing, customer and operator user interface, etc. The pay depends on experience but is good. Isn't it better to use Erlang for the http and dns server ? I don't really like the syntax, but you have many things already implemented. Unfortunately Haskell is not yet ready for this task. http://eddie.sourceforge.net/what.html http://yaws.hyber.org/ Umm... http and dns? You're kidding right? Half of hackage.haskell.org is devoted to networking tasks. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
wchogg: On Thu, Jan 8, 2009 at 8:32 AM, John A. De Goes j...@n-brain.net wrote: Haskell's networking support is very rudimentary. Erlang's is quite sophisticated. For network intensive applications, especially those requiring messaging, fault-tolerance, distribution, and so forth, there's no doubt that Erlang is a more productive choice. Not because of the language, per se, but because of all the stuff that is packaged with it, or available for it. Now I understand that there aren't(?) any Haskell implementations that can act as distributed nodes the way the Erlang implementation can, but I'm not familiar enough with Erlang to understand what it has for networking that the Haskell network packages don't have. Could you explain a bit further? I've been thinking a lot about network programming anyway lately am looking for library opportunities. Note that there even exists an FFI binding to Erlang for Haskell, so that Haskell nodes can seamlessly interact with other nodes speaking Erlang's protocol format. There's nothing stopping you using Haskell nodes in a distributed fashion, and indeed there are groups doing this. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
There's a JavaScript binding to Java, and there's a Java binding to Erlang, so nothing's stopping you from using JavaScript nodes in a distributed fashion -- if you have a weird obsession with proving that JavaScript is well-suited for every task. But really, what's the point? FFI code is fragile, often uncompilable and unsupported, and doesn't observe the idioms of Haskell nor take advantage of its powerful language features. Rather than coding through FFI, a messaging application is better off written in 100% Erlang, because the libraries are native there and so confer all the benefits unique to native libraries. You can indeed fit a square peg in a round hole, if you pound hard enough. That doesn't mean it's a good thing to do. Here's hoping someone develops a native messaging framework for Haskell, which is the equal of RabbitMQ. Regards, John On Jan 8, 2009, at 11:06 AM, Don Stewart wrote: wchogg: On Thu, Jan 8, 2009 at 8:32 AM, John A. De Goes j...@n-brain.net wrote: Haskell's networking support is very rudimentary. Erlang's is quite sophisticated. For network intensive applications, especially those requiring messaging, fault-tolerance, distribution, and so forth, there's no doubt that Erlang is a more productive choice. Not because of the language, per se, but because of all the stuff that is packaged with it, or available for it. Now I understand that there aren't(?) any Haskell implementations that can act as distributed nodes the way the Erlang implementation can, but I'm not familiar enough with Erlang to understand what it has for networking that the Haskell network packages don't have. Could you explain a bit further? I've been thinking a lot about network programming anyway lately am looking for library opportunities. Note that there even exists an FFI binding to Erlang for Haskell, so that Haskell nodes can seamlessly interact with other nodes speaking Erlang's protocol format. There's nothing stopping you using Haskell nodes in a distributed fashion, and indeed there are groups doing this. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 8, 2009 at 12:06 PM, Don Stewart d...@galois.com wrote: wchogg: On Thu, Jan 8, 2009 at 8:32 AM, John A. De Goes j...@n-brain.net wrote: Haskell's networking support is very rudimentary. Erlang's is quite sophisticated. For network intensive applications, especially those requiring messaging, fault-tolerance, distribution, and so forth, there's no doubt that Erlang is a more productive choice. Not because of the language, per se, but because of all the stuff that is packaged with it, or available for it. Now I understand that there aren't(?) any Haskell implementations that can act as distributed nodes the way the Erlang implementation can snip There's nothing stopping you using Haskell nodes in a distributed fashion, and indeed there are groups doing this. Didn't realize it was charted territory. Sorry about that. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
John A. De Goes wrote: Here's hoping someone develops a native messaging framework for Haskell, which is the equal of RabbitMQ. The first thing would be to make a Haskell client library to speak AMQP (Advanced Message Queuing Protocol) on the wire. It is a very open binary standard (with defined semantics!) at http://jira.amqp.org/confluence/display/AMQP/Advanced+Message+Queuing+Protocol I would be mildly surprised if zero people were working on this. Once that is in place then the question of a Haskell Broker for AMQP arises. But I suspect that Erlang's runtime will still rule there for production use. -- Chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HookedBuildInfo and Cabal
Hi Brian everyone, Got this bug report, which appears to be related to your autoconf patch. Did you test it on Windows? As a more general question, how can one use Cabal to detect PostgreSQL paths in a way that works with both GHC 6.8 and 6.10? The commit here was: commit 57c723873b020643b9062941a2ece130cd0f36c6 Author: Brian Bloniarz phun...@hotmail.com Date: Fri Dec 26 14:33:43 2008 -0500 Update hdbc-postgresql for GHC 6.10 Cabal 1.6. This switches over to use autoconf rathe r than Cabal hooks to detect postgres paths; there's no backwards-compatible way to use write HookedBuildInfo with Cabal 1.2 and Cabal 1.6 (see http://www.haskell.org/pipermail/glasgow-ha skell-users/2008-October/015707.html) -- John - Forwarded message from software-nore...@complete.org - From: software-nore...@complete.org Date: Thu, 08 Jan 2009 12:37:12 -0600 Subject: [HDBC PostgreSQL driver - Bug #131] Throw exception when use data type timpstamp without time zone Issue #131 has been updated by Benjamin Cao. by the way, I cannot configure 1.1.6.0.0 successfully on my windows OS because of the Expr command(which is a linux command, even if I got a windows version of it, it keep crash on windows.) The function isFixedPointUnderConversionToLocalTime in 1.1.6.0.0 is the same. So I think it should be a same issue on 1.1.6.0.0 Bug #131: Throw exception when use data type timpstamp without time zone http://software.complete.org/software/issues/show/131 Author: Benjamin Cao Status: New Priority: Normal Assigned to: Category: Target version: 1.1.4.1.0 Resolution: The database is like CREATE TABLE test ( name character varying(200) NOT NULL, time timestamp with time zone, timenotz timestamp without time zone, CONSTRAINT test_pkey PRIMARY KEY (name) ) WITH (OIDS=FALSE); ALTER TABLE test OWNER TO postgres; when call st - prepare c select name,time, timenotz from test execute st [] Will get this error: Time.toClockTime: timezone offset out of range So I modified the function in statement.hsc to: isFixedPointUnderConversionToLocalTime calTime = do let hasError = False calTime' - Control.Exception.catch (toLocalCalTime calTime) (\_-do let hasError = True return calTime) if hasError then return False else return $ eqParts calTime calTime' You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://software.complete.org/software/my/account - End forwarded message - ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: How to give unique name/id to nodes outside any monad ?
Interestingly, I failed to detect sharing with StableName. But using the graph node as a key turned to work... If you're interested in the experiment, see attached code. Cheers, Thu 2009/1/8 minh thu not...@gmail.com: 2009/1/8 Ertugrul Soeylemez e...@ertes.de: minh thu not...@gmail.com wrote: Nothing, simply the notation. Now, with the remark of Luke, I'm wondering how bad it is to use makeStableName/hashStableName to copy the data structure in a similar one with explicit reference (that is, using pointer or keys in a map or whatever). Probably you're misusing the notation. I don't see any reason, why monadic notation should be less readable. Usually it's even more readable. Luke's remark is very valid. Haskell is the wrong language for imperative programming. You don't have _any_ benefit of Haskell, if you use it like C. Try to change your mind. Monads aren't evil. They are there to make your life easier. Way easier than imperative methods. Well, maybe it's is just my opinion, but I found the non-monadic code in the previous mail easier to write than the monadic one... I don't know against what you're making the compareason to say it's more readable. Although I agree using Haskell requires some change of thinking, statement like yours are a bit too much for me. I find Haskell a nice language even for imperative programming... Cheers, Thu Greets, Ertugrul. Thank you, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Look at http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-StableName.html. But what's wrong with constructing the graph in a monad? On Thu, Jan 8, 2009 at 9:53 AM, minh thu not...@gmail.com wrote: Well, the processing of the data structure has to be done in the IO monad. What is the library you talk about ? Could it give the stable names (in IO) for each node of the mentioned graph (I mean, after the graph has been constructed purely) ? Thanks, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- nightmare = unsafePerformIO (getWrongWife = sex) http://blog.ertes.de/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- 2009.01.08 -- 2009.01.08 -- -- Given a graph following this type -- -- data DS = A [DS] String | B String, -- -- the problem is to detect sharing so -- that shared nodes are used only once -- (for instance to output the name of -- the node or to malloc it, ...). -- -- Here, the goal is to clone the graph -- into the following type -- -- type NDS = [(Int,N)] -- data N = NA [Int] String | B String -- -- that is, each child of A is an Int in -- a association list (N means 'named'). -- -- I see two possibility based on a Map -- mapping already processed node to their -- name : -- - Map DS Int -- - Map Int Int -- -- The key in the first possibility is the -- processed node itself. This mean it should be -- an instance of Ord and the graph should be -- acyclic. -- -- The key in the second possibility is given -- as the hash of the StableName of the node. -- This need to be done in the IO monad. -- This FAILS to detect the sharing. -- -- Another possibility, which doesn't respect -- exactly the problem as given above, is to -- produce the graph directly in a monad that -- holds the book-keeping of the name. -- (Not implemented here.) -- module Graph where import Data.Map import
Re: [Haskell-cafe] State Monad - using the updated state
I think I've got this now - thanks to you all for the superb advice! The reason I cannot increment state inside main is because main is not a State monad (it's an IO monad). Thus in order to use my State Monad, I have execute inside a State monad as that the state is encapsulated in there. I'll have to have a think about how I'm going to structure the rest of my code inside something like Ryan's randomComputation example - the basic example works perfectly! I'm writing a Monte Carlo simulator for financial portfolios - it's something I've done in several languages so I often use it to test drive a new language. Most imperative implementations of this sort thing are very state-heavy, so I thought it would fun to re-think it a bit in Haskell. My initial thoughts before delving into Monads was to take advantage of Haskell's lazy evaluation and create an 'infinite' list of randoms using something like the below: ranq1List :: (Word64 - a ) - Word64 - [a] ranq1List converter state = converter newState : ranq1List converter newState where newState = ranq1Increment state This works fine - the converter is an extra parameter that carrys a partially defined function used to numerically translate from word64-whatever_type__we_want as stipulated in Numerical Recipes' C++ example. It was at this point I felt it was getting a bit ugly and started to look at Monads (plus I wanted to see what all 'fuss' was about with Monads too!). One more question on this - the other concern I had with the recursive list approach was that although lazy evaluation prevents me generating numbers before I 'ask' for them, I figured that if I was going to be asking for say 10 million over the course of one simulation, that although I request them one by one, over hours or even days, at the end of the simulation I will still have a list of 10 million word64s - each of which I could throw away within minutes of asking for it. This seemed like huge memory bloat, and thus probably I was taking the wrong approach. I'd be interested to know if you have any thoughts on the various solutions? Ryan's randomComputation strikes me as the most practical and there's an old adage that if a language provides a facility (i.e. The State Monad here), you shouldn't be rewriting similar functionality yourself unless there is a very very good reason to go it alone. Thus I figure that Haskell's State Monad used as described is always going to beat anything I come up with to do the same thing - unless I spend an awful lot of time tailoring a specific solution. If you think there is a nicer non-Monadic, pure solution to this type of problem, I'd be interested to hear them. Thanks again for all your help, Phil. On 08/01/2009 13:27, Kurt Hutchinson kelansli...@gmail.com wrote: Ryan gave some great advice about restructuring your program to do what you want, but I wanted to give a small explanation of why that's necessary. 2009/1/7 Phil pbeadl...@mail2web.com: I want to be able to do: Get_a_random_number a whole load of other stuff Get the next number as defined by the updated state in the first call some more stuff Get another number, and so on. The issue you're having is that you're trying to do the other stuff in your 'main', but main isn't inside the State monad. The only State computation you're calling from main is getRanq1, but you really need another State computation that does other stuff and calls getRanq1 itself. That's what Ryan's first suggestion implements. You need all your other stuff to be done inside the State monad so that it has read/update access to the current random state. So all your main does is run a State computation. That computation calls getRanq1 itself and then other stuff in between calls to getRanq1. Does that make sense? Kurt ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Jan 8, 2009, at 12:56 PM, Tim Newsham wrote: You replied to someone discussing using Haskell at a CDN to implement things like web servers by saying that Haskell wasn't suitable for the task. That is incorrect. I replied to Achim's message asking for elaboration on Haskell's unsuitability. It was a convenient point to discuss Haskell's networking deficiencies. Regards, John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Inconsistency in support for phantom types?
Hi, I have run into what appears to be an inconsistency in the support for using phantom types to parameterize other types. Here's an example (don't pay too much attention to the maths, it's just there to motivate the example). I want to define types for the finite fields with 2, 3 and 5 elements (clock arithmetic modulo 2, 3 or 5). {-# OPTIONS_GHC -fglasgow-exts #-} class IntegerAsType a where value :: a - Integer -- three phantom types: data T2 instance IntegerAsType T2 where value _ = 2 data T3 instance IntegerAsType T3 where value _ = 3 data T5 instance IntegerAsType T5 where value _ = 5 newtype Fp n = Fp Integer deriving (Eq,Ord) -- our three finite field types: type F2 = Fp T2 type F3 = Fp T3 type F5 = Fp T5 -- Show and Num instances instance Show (Fp n) where show (Fp x) = show x instance IntegerAsType n = Num (Fp n) where Fp x + Fp y = Fp $ (x+y) `mod` value (undefined :: n) negate (Fp 0) = 0 negate (Fp x) = Fp $ value (undefined :: n) - x Fp x * Fp y = Fp $ (x*y) `mod` value (undefined :: n) fromInteger m = Fp $ m `mod` value (undefined :: n) Now, we can also define a Fractional instance, using the extended Euclid algorithm (given at the end) -- n must be prime instance IntegerAsType n = Fractional (Fp n) where recip 0 = error Fp.recip 0 recip (Fp x) = let p = value (undefined :: n) (u,v,1) = extendedEuclid x p -- so ux+vp = 1. (We know the gcd is 1 as p prime) in Fp $ u `mod` p Now, the problem I've run into is, what do I do if I want to define a function parameterised over the phantom types, but without doing it as part of a type class instance? For example, suppose that I had just wanted to define inv as a synonym for recip: inv :: IntegerAsType n = Fp n - Fp n inv 0 = error Fp,inv 0 inv (Fp x) = let p = value (undefined :: n) (u,v,1) = extendedEuclid x p in Fp $ u `mod` p inv has exactly the same code as recip, but now the IntegerAsType constraint is part of the type signature, rather than an instance constraint. It seems that this means that the constraint is not available to the code during compilation, because when I try to compile this I get Ambiguous type variable `n' in the constraint: `IntegerAsType n' arising from a use of `value' at Test.hs:52:21-42 Probable fix: add a type signature that fixes these type variable(s) It seems to me highly desirable that this code should compile as expected, just as the recip code compiles. Is it a bug in GHC, or a missing language feature, or is there a better way to do what I'm trying to do? Thanks, David -- extendedEuclid a b returns (u,v,d) such that u*a + v*b = d extendedEuclid a b | a = 0 b = 0 = extendedEuclid' a b [] where extendedEuclid' d 0 qs = let (u,v) = unwind 1 0 qs in (u,v,d) extendedEuclid' a b qs = let (q,r) = quotRem a b in extendedEuclid' b r (q:qs) unwind u v [] = (u,v) unwind u v (q:qs) = unwind v (u-v*q) qs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 8, 2009 at 2:02 PM, John A. De Goes j...@n-brain.net wrote: On Jan 8, 2009, at 12:56 PM, Tim Newsham wrote: You replied to someone discussing using Haskell at a CDN to implement things like web servers by saying that Haskell wasn't suitable for the task. That is incorrect. I replied to Achim's message asking for elaboration on Haskell's unsuitability. It was a convenient point to discuss Haskell's networking deficiencies. Part of the problem I'm having with this discussion, though, is that it's still not clear to me what critical features are lacking. I know you've said Haskell doesn't have anything quite like the Erlang OTP library, but that doesn't really help me much. I've only looked a little at OTP I don't think I understand what you get from its behaviors that you don't get from Control.Concurrent + mtl, i.e. various forms of state error handling independent of the concurrency underneath. Can you elucidate a bit more? I don't want the conversation to degenerate. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Inconsistency in support for phantom types?
On Thu, Jan 8, 2009 at 3:11 PM, DavidA polyom...@f2s.com wrote: Hi, I have run into what appears to be an inconsistency in the support for using phantom types to parameterize other types. Here's an example (don't pay too much attention to the maths, it's just there to motivate the example). I want to define types for the finite fields with 2, 3 and 5 elements (clock arithmetic modulo 2, 3 or 5). {-# OPTIONS_GHC -fglasgow-exts #-} class IntegerAsType a where value :: a - Integer -- three phantom types: data T2 instance IntegerAsType T2 where value _ = 2 data T3 instance IntegerAsType T3 where value _ = 3 data T5 instance IntegerAsType T5 where value _ = 5 newtype Fp n = Fp Integer deriving (Eq,Ord) -- our three finite field types: type F2 = Fp T2 type F3 = Fp T3 type F5 = Fp T5 -- Show and Num instances instance Show (Fp n) where show (Fp x) = show x instance IntegerAsType n = Num (Fp n) where Fp x + Fp y = Fp $ (x+y) `mod` value (undefined :: n) negate (Fp 0) = 0 negate (Fp x) = Fp $ value (undefined :: n) - x Fp x * Fp y = Fp $ (x*y) `mod` value (undefined :: n) fromInteger m = Fp $ m `mod` value (undefined :: n) Now, we can also define a Fractional instance, using the extended Euclid algorithm (given at the end) -- n must be prime instance IntegerAsType n = Fractional (Fp n) where recip 0 = error Fp.recip 0 recip (Fp x) = let p = value (undefined :: n) (u,v,1) = extendedEuclid x p -- so ux+vp = 1. (We know the gcd is 1 as p prime) in Fp $ u `mod` p Now, the problem I've run into is, what do I do if I want to define a function parameterised over the phantom types, but without doing it as part of a type class instance? For example, suppose that I had just wanted to define inv as a synonym for recip: inv :: IntegerAsType n = Fp n - Fp n inv 0 = error Fp,inv 0 inv (Fp x) = let p = value (undefined :: n) (u,v,1) = extendedEuclid x p in Fp $ u `mod` p inv has exactly the same code as recip, but now the IntegerAsType constraint is part of the type signature, rather than an instance constraint. It seems that this means that the constraint is not available to the code during compilation, because when I try to compile this I get Ambiguous type variable `n' in the constraint: `IntegerAsType n' arising from a use of `value' at Test.hs:52:21-42 Probable fix: add a type signature that fixes these type variable(s) It seems to me highly desirable that this code should compile as expected, just as the recip code compiles. Is it a bug in GHC, or a missing language feature, or is there a better way to do what I'm trying to do? Type variables don't scope over function definitions, so your example is equivalent to: inv :: IntegerAsType n = Fp n - Fp n inv 0 = error Fp,inv 0 inv (Fp x) = let p = value (undefined :: a) (u,v,1) = extendedEuclid x p in Fp $ u `mod` p In GHC, you can use the ScopedTypeVariables extension to avoid that problem. (See section 8.8.6 of the manual.) {-# LANGUAGE ScopedTypeVariables #-} ... inv :: forall n. IntegerAsType n = Fp n - Fp n inv 0 = error Fp,inv 0 inv (Fp x) = let p = value (undefined :: n) (u,v,1) = extendedEuclid x p in Fp $ u `mod` p Or, for Haskell 98 compatibility, you can use a function to transform the types. getFpType :: Fp n - n getFpType _ = undefined inv :: IntegerAsType n = Fp n - Fp n inv 0 = error Fp,inv 0 inv n@(Fp x) = let p = value (getFpType n) (u,v,1) = extendedEuclid x p in Fp $ u `mod` p -- Dave Menendez d...@zednenem.com http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 08, 2009 at 10:36:32AM -0700, John A. De Goes wrote: The number of applications requiring the implementation of a custom web server is an insignificant fraction of the number of applications requiring a messaging system. I don't think anyone would dispute Haskell's ability to do low-level, raw networking, of the type that few people actually need to do. It's the higher level stuff where there's a huge amount of room for improvement. I disagree on both points. Haskell has had somewhat of a deficit in the low-level networking stuff, not even supporting IPv6 in the standard stack until just recently. (That is, things like AF_INET6 were not present.) I think it has pretty much caught up by now though. On the other hand, I see nothing in Haskell that would prevent its use for any of your purposes. There are numerous high-level web infrastructures already. Perhaps they are more or less suited to your needs, but that's a library issue, not a language issue. Saying WASH sucks or Happs sucks is like saying rails sucks. May or may not be true, but it doesn't imply anything about whether Haskell is suited to that problem domain. And much as I detest Rails, it doesn't necessarily mean that Ruby *must* suck for web apps. -- John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Inconsistency in support for phantom types?
On Thu, 2009-01-08 at 20:11 +, DavidA wrote: Hi, I have run into what appears to be an inconsistency in the support for using phantom types to parameterize other types. Here's an example (don't pay too much attention to the maths, it's just there to motivate the example). I want to define types for the finite fields with 2, 3 and 5 elements (clock arithmetic modulo 2, 3 or 5). ... Now, the problem I've run into is, what do I do if I want to define a function parameterised over the phantom types, but without doing it as part of a type class instance? For example, suppose that I had just wanted to define inv as a synonym for recip: inv :: IntegerAsType n = Fp n - Fp n inv 0 = error Fp,inv 0 inv (Fp x) = let p = value (undefined :: n) (u,v,1) = extendedEuclid x p in Fp $ u `mod` p inv has exactly the same code as recip, but now the IntegerAsType constraint is part of the type signature, rather than an instance constraint. It seems that this means that the constraint is not available to the code during compilation, because when I try to compile this I get Ambiguous type variable `n' in the constraint: `IntegerAsType n' arising from a use of `value' at Test.hs:52:21-42 Probable fix: add a type signature that fixes these type variable(s) It seems to me highly desirable that this code should compile as expected, just as the recip code compiles. Is it a bug in GHC, or a missing language feature, It's missing in Haskell 98. If you add the pragma {-# LANGUAGE ScopedTypeVariables #-} then GHC (at least) will accept the variant syntax inv :: forall n. IntegerAsType n = Fp n - Fp n and the definition as you gave it. Since Haskell 98 doesn't have any feature like this, GHC can't really introduce it without requiring you to deviate from Haskell 98 syntax as well :( jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Jan 8, 2009, at 12:56 PM, Tim Newsham wrote: You replied to someone discussing using Haskell at a CDN to implement things like web servers by saying that Haskell wasn't suitable for the task. That is incorrect. I replied to Achim's message asking for elaboration on Haskell's unsuitability. It was a convenient point to discuss Haskell's networking deficiencies. Oops. My apologies. Regards, John Tim Newsham http://www.thenewsh.com/~newsham/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Inconsistency in support for phantom types?
On 8 Jan 2009, at 23:11, DavidA wrote: inv :: IntegerAsType n = Fp n - Fp n ^ ^ ^ this n --+---+---| inv 0 = error Fp,inv 0 inv (Fp x) = let p = value (undefined :: n) ^ and this one --| are different beasts. You can try something like this: getN :: Fp n - n getN _ = undefined inv a@(Fp x) = let p = value $ getN a ... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hypothetical Haskell job in New York
Don Stewart ha scritto: manlio_perillo: Tony Hannan ha scritto: Let me give you more information about this hypothetical job posting. Our company is a startup CDN (http://en.wikipedia.org/wiki/Content_Delivery_Network) about 3 years old and doing well. You would hythothetically be one of 7 programmer who write all the software involved in a CDN including http server, dns server, monitoring, load balancing, customer and operator user interface, etc. The pay depends on experience but is good. Isn't it better to use Erlang for the http and dns server ? I don't really like the syntax, but you have many things already implemented. Unfortunately Haskell is not yet ready for this task. http://eddie.sourceforge.net/what.html http://yaws.hyber.org/ Umm... http and dns? You're kidding right? Half of hackage.haskell.org is devoted to networking tasks. I'm speaking about servers, not clients. How much of pure Haskell internet servers are used in a production environment, in the open internet (and not in restricted LANs)? How much traffic they handle? How hard are to maintain/update/develope/? Personally, I only know http://hpaste.org/, based on Server: HAppS/0.8.4 And about HAppS, I'm not an Haskell expert, but reading the source I see that static files are server (in the HTTP server) using Data.ByteString.Lazy's hGetContents Is this ok? -- Don Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] advanced class constraints in Haskell 98?
GHC accepts a class declaration like class Monad (m Maybe) = C m where ... without having any language extension switched on. But it isn't Haskell 98, is it? Hugs 2005 also accepts this. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
John Goerzen ha scritto: On Thu, Jan 08, 2009 at 10:36:32AM -0700, John A. De Goes wrote: [...] On the other hand, I see nothing in Haskell that would prevent its use for any of your purposes. There are numerous high-level web infrastructures already. Perhaps they are more or less suited to your needs, but that's a library issue, not a language issue. The question is not about Haskell language. I think that Haskell is far better than Erlang, and in fact I'm studying Haskell and not Erlang; and one of the reason I choosed Haskell is for its support to concurrency. The problem, IMHO, is with the availability of solid, production ready servers implemented in Haskell, that can be used as case study. The major web framework in Haskell is HAppS, if I'm correct, and yet in the HAppS code I see some things that make me worry about the robustess of the code. I you grep for hGetsContent, it appears in place where I'm not sure if it is safe to use. One example is in serving static files. Another example is the multipart parser: -- | Read a multi-part message from a 'Handle'. -- Fails on parse errors. hGetMultipartBody :: String -- ^ Boundary - Handle - IO MultiPart hGetMultipartBody b h = do s - BS.hGetContents h case parseMultipartBody b s of Nothing - fail Error parsing multi-part message Just m - return m Now, if you read the paper about iteratee: http://okmij.org/ftp/Haskell/Iteratee/ you should have doubts about how robust all of this is. The other problem is with the use of select in the GHC runtime for IO multiplexing. I know that things works, but using select in a server that should support many concurrent requests, is not really what you really want. Regards Manlio Perillo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advanced class constraints in Haskell 98?
On 8 Jan 2009, at 23:59, Henning Thielemann wrote: GHC accepts a class declaration like class Monad (m Maybe) = C m where ... without having any language extension switched on. But it isn't Haskell 98, is it? It is. From Report: A class assertion has form qtycls tyvar, and indicates the membership of the type tyvar in the class qtycls. A class identifier begins with an uppercase letter. A context consists of zero or more class assertions, and has the general form ( C1 u1, ..., Cn un ) where C1, ..., Cn are class identifiers, and each of the u1, ..., un is either a type variable, or the application of type variable to one or more types. atype is defined as atype- gtycon | tyvar | ( type1 , ... , typek ) (tuple type, k=2) | [ type ](list type) | ( type )(parenthesised constructor) Hugs 2005 also accepts this. ___ 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: How to give unique name/id to nodes outside any monad ?
Using StableName is really a last resort when you need to do low level strange things. I would not use it when there's another way. Which there is. -- Lennart 2009/1/8 minh thu not...@gmail.com: Interestingly, I failed to detect sharing with StableName. But using the graph node as a key turned to work... If you're interested in the experiment, see attached code. Cheers, Thu 2009/1/8 minh thu not...@gmail.com: 2009/1/8 Ertugrul Soeylemez e...@ertes.de: minh thu not...@gmail.com wrote: Nothing, simply the notation. Now, with the remark of Luke, I'm wondering how bad it is to use makeStableName/hashStableName to copy the data structure in a similar one with explicit reference (that is, using pointer or keys in a map or whatever). Probably you're misusing the notation. I don't see any reason, why monadic notation should be less readable. Usually it's even more readable. Luke's remark is very valid. Haskell is the wrong language for imperative programming. You don't have _any_ benefit of Haskell, if you use it like C. Try to change your mind. Monads aren't evil. They are there to make your life easier. Way easier than imperative methods. Well, maybe it's is just my opinion, but I found the non-monadic code in the previous mail easier to write than the monadic one... I don't know against what you're making the compareason to say it's more readable. Although I agree using Haskell requires some change of thinking, statement like yours are a bit too much for me. I find Haskell a nice language even for imperative programming... Cheers, Thu Greets, Ertugrul. Thank you, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Look at http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-StableName.html. But what's wrong with constructing the graph in a monad? On Thu, Jan 8, 2009 at 9:53 AM, minh thu not...@gmail.com wrote: Well, the processing of the data structure has to be done in the IO monad. What is the library you talk about ? Could it give the stable names (in IO) for each node of the mentioned graph (I mean, after the graph has been constructed purely) ? Thanks, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- nightmare = unsafePerformIO (getWrongWife = sex) http://blog.ertes.de/ ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advanced class constraints in Haskell 98?
On Fri, 9 Jan 2009, Miguel Mitrofanov wrote: On 8 Jan 2009, at 23:59, Henning Thielemann wrote: GHC accepts a class declaration like class Monad (m Maybe) = C m where ... without having any language extension switched on. But it isn't Haskell 98, is it? It is. From Report: A class assertion has form qtycls tyvar, and indicates the membership of the type tyvar in the class qtycls. A class identifier begins with an uppercase letter. A context consists of zero or more class assertions, and has the general form ( C1 u1, ..., Cn un ) where C1, ..., Cn are class identifiers, and each of the u1, ..., un is either a type variable, or the application of type variable to one or more types. A nice. I jumped into 4.3 and found § § R 32 © ¦ 6 © ¦ 32 ¢ R ¨ © ¥ 7  ¤ ¢¨ 7 5© ¥  ¦ class =where ¢ § § § § ¥  ¦ ¡ 2 § 6 © R© 7 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advanced class constraints in Haskell 98?
On Thu, 8 Jan 2009, Henning Thielemann wrote: On Fri, 9 Jan 2009, Miguel Mitrofanov wrote: On 8 Jan 2009, at 23:59, Henning Thielemann wrote: GHC accepts a class declaration like class Monad (m Maybe) = C m where ... without having any language extension switched on. But it isn't Haskell 98, is it? It is. From Report: A class assertion has form qtycls tyvar, and indicates the membership of the type tyvar in the class qtycls. A class identifier begins with an uppercase letter. A context consists of zero or more class assertions, and has the general form ( C1 u1, ..., Cn un ) where C1, ..., Cn are class identifiers, and each of the u1, ..., un is either a type variable, or the application of type variable to one or more types. A nice. I jumped into 4.3 and found § § R 32 © ... copying from Haskell 98 report did not only insert rubbish, but also triggered sending the e-mail. I hope it did not more damage ... scontext - simpleclass | (simpleclass_1, ..., simpleclass_n) simpleclass - qtycls tyvar So it must be 'atype' instead of 'tyvar'? Haskell 98 is really mighty.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
Manlio Perillo wrote: John Goerzen ha scritto: On Thu, Jan 08, 2009 at 10:36:32AM -0700, John A. De Goes wrote: [...] On the other hand, I see nothing in Haskell that would prevent its use for any of your purposes. There are numerous high-level web infrastructures already. Perhaps they are more or less suited to your needs, but that's a library issue, not a language issue. The question is not about Haskell language. I think that Haskell is far better than Erlang, and in fact I'm studying Haskell and not Erlang; and one of the reason I choosed Haskell is for its support to concurrency. The problem, IMHO, is with the availability of solid, production ready servers implemented in Haskell, that can be used as case study. The major web framework in Haskell is HAppS, if I'm correct, and yet in the HAppS code I see some things that make me worry about the robustess of the code. [--snip--] Indeed. I've been looking for a Haskell HTTP server implementation that can actually handle file serving using strictly limited memory (for a simple UPnP server, as of yet unreleased) and that also doesn't leak handles like a sieve, but I haven't found anything yet. I don't know, maybe my hackage-foo is lacking. In the end I just rolled my own implementation using the HTTP package for parsing requests and doing all the socket I/O myself using low-level primitives. It seemed to be the only way to guarantee reasonable resource usage while serving multi-gigabyte files to fickle HTTP clients that like to drop connections willy-nilly. Don't get me wrong -- the socket support is pretty decent, but there are also some weird idiosyncrasies, for example requiring that the PortNum is specified in network byte order and lacking a function to convert host-network byte order (hton). Oleg's Iteratee does look very interesting though. Maybe I'll have a go at trying to use his ideas in my UPnP server. Cheers, Bardur Arantsson ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] State Monad - using the updated state
On Thu, Jan 8, 2009 at 12:56 PM, Phil pbeadl...@mail2web.com wrote: One more question on this - the other concern I had with the recursive list approach was that although lazy evaluation prevents me generating numbers before I 'ask' for them, I figured that if I was going to be asking for say 10 million over the course of one simulation, that although I request them one by one, over hours or even days, at the end of the simulation I will still have a list of 10 million word64s - each of which I could throw away within minutes of asking for it. This seemed like huge memory bloat, and thus probably I was taking the wrong approach. if you don't hold on to the whole list, i.e. you use the head of the list and then pass the tail around, the garbage collector will collect the unused prefix. In Haskell lists are used like loops. If a list is used in a sufficiently forgetful fashion, it will use constant space. Luke I'd be interested to know if you have any thoughts on the various solutions? Ryan's randomComputation strikes me as the most practical and there's an old adage that if a language provides a facility (i.e. The State Monad here), you shouldn't be rewriting similar functionality yourself unless there is a very very good reason to go it alone. Thus I figure that Haskell's State Monad used as described is always going to beat anything I come up with to do the same thing - unless I spend an awful lot of time tailoring a specific solution. If you think there is a nicer non-Monadic, pure solution to this type of problem, I'd be interested to hear them. Thanks again for all your help, Phil. On 08/01/2009 13:27, Kurt Hutchinson kelansli...@gmail.com wrote: Ryan gave some great advice about restructuring your program to do what you want, but I wanted to give a small explanation of why that's necessary. 2009/1/7 Phil pbeadl...@mail2web.com: I want to be able to do: Get_a_random_number a whole load of other stuff Get the next number as defined by the updated state in the first call some more stuff Get another number, and so on. The issue you're having is that you're trying to do the other stuff in your 'main', but main isn't inside the State monad. The only State computation you're calling from main is getRanq1, but you really need another State computation that does other stuff and calls getRanq1 itself. That's what Ryan's first suggestion implements. You need all your other stuff to be done inside the State monad so that it has read/update access to the current random state. So all your main does is run a State computation. That computation calls getRanq1 itself and then other stuff in between calls to getRanq1. Does that make sense? Kurt ___ 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: Hypothetical Haskell job in New York
On Thu, 8 Jan 2009, Manlio Perillo wrote: Personally, I only know http://hpaste.org/, based on Server: HAppS/0.8.4 I'm using a modified HWS for the parallel webs, e.g. the Real Monad Transformer: http://www.haskell.org.monadtransformer.parallelnetz.de/haskellwiki/Category:Monad However, recently a lot of accesses made the server quite unusable. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
PortNum is specified in network byte order and lacking a function to convert host-network byte order (hton). Perhaps this is another argument for my thread from a while back? http://www.nabble.com/Missing-Network-Functions-td21188779.html /jve On Thu, Jan 8, 2009 at 4:37 PM, Bardur Arantsson s...@scientician.netwrote: Manlio Perillo wrote: John Goerzen ha scritto: On Thu, Jan 08, 2009 at 10:36:32AM -0700, John A. De Goes wrote: [...] On the other hand, I see nothing in Haskell that would prevent its use for any of your purposes. There are numerous high-level web infrastructures already. Perhaps they are more or less suited to your needs, but that's a library issue, not a language issue. The question is not about Haskell language. I think that Haskell is far better than Erlang, and in fact I'm studying Haskell and not Erlang; and one of the reason I choosed Haskell is for its support to concurrency. The problem, IMHO, is with the availability of solid, production ready servers implemented in Haskell, that can be used as case study. The major web framework in Haskell is HAppS, if I'm correct, and yet in the HAppS code I see some things that make me worry about the robustess of the code. [--snip--] Indeed. I've been looking for a Haskell HTTP server implementation that can actually handle file serving using strictly limited memory (for a simple UPnP server, as of yet unreleased) and that also doesn't leak handles like a sieve, but I haven't found anything yet. I don't know, maybe my hackage-foo is lacking. In the end I just rolled my own implementation using the HTTP package for parsing requests and doing all the socket I/O myself using low-level primitives. It seemed to be the only way to guarantee reasonable resource usage while serving multi-gigabyte files to fickle HTTP clients that like to drop connections willy-nilly. Don't get me wrong -- the socket support is pretty decent, but there are also some weird idiosyncrasies, for example requiring that the PortNum is specified in network byte order and lacking a function to convert host-network byte order (hton). Oleg's Iteratee does look very interesting though. Maybe I'll have a go at trying to use his ideas in my UPnP server. Cheers, Bardur Arantsson ___ 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: Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 08, 2009 at 10:37:55PM +0100, Bardur Arantsson wrote: Don't get me wrong -- the socket support is pretty decent, but there are also some weird idiosyncrasies, for example requiring that the PortNum is specified in network byte order and lacking a function to convert host-network byte order (hton). Look at Haddock for PortNumber: newtype PortNumber Constructors PortNum Word16 Instances Enum PortNumber Eq PortNumber Integral PortNumber Num PortNumber Ord PortNumber Real PortNumber Show PortNumber Typeable PortNumber Storable PortNumber Try it in ghci: Prelude Network.Socket 15 :: PortNumber 15 Prelude Network.Socket PortNum 15 3840 Prelude Network.Socket (fromIntegral (15::Int))::PortNumber 15 So, in essence, there are *many* functions that let you do this. You should not be needing to construct PortNum by hand. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 08, 2009 at 11:14:18AM -0700, John A. De Goes wrote: But really, what's the point? FFI code is fragile, often uncompilable and unsupported, and doesn't observe the idioms of Haskell nor take advantage of its powerful language features. Rather than coding through That is an extraordinarily cruel, and inaccurate, sweep of FFI. I've worked with C bindings to several high-level languages, and I must say that I like FFI the best of any I've used. It's easy to use correctly, stable, and solid. If anything, it suffers from under-documentation. The whole point of FFI is to bring other languages into the Haskell fold. So you can, say, talk to a database using its C library and wind up putting the strongly-typed HaskellDB atop it. Or you can write an MD5 algorithm in C and make it look like a regular Haskell function. You can indeed fit a square peg in a round hole, if you pound hard enough. That doesn't mean it's a good thing to do. And with that, I fully agree. -- Joh ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Monads aren't evil
Hello fellow Haskellers, When I read questions from Haskell beginners, it somehow seems like they try to avoid monads and view them as a last resort, if there is no easy non-monadic way. I'm really sure that the cause for this is that most tutorials deal with monads very sparingly and mostly in the context of input/output. Also usually monads are associated with the do-notation, which makes them appear even more special, although there is really nothing special about them. I appeal to all experienced Haskell programmers, especially to tutorial writers, to try to focus more on how monads are nothing special, when talking to beginners. Let me tell you that usually 90% of my code is monadic and there is really nothing wrong with that. I use especially State monads and StateT transformers very often, because they are convenient and are just a clean combinator frontend to what you would do manually without them: passing state. Greets, Ertugrul. -- nightmare = unsafePerformIO (getWrongWife = sex) http://blog.ertes.de/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hypothetical Haskell job in New York
On Thu, Jan 08, 2009 at 09:46:36PM +0100, Manlio Perillo wrote: I'm speaking about servers, not clients. How much of pure Haskell internet servers are used in a production environment, in the open internet (and not in restricted LANs)? Does that really matter? I tend to judge technology based on its merits for my work, not on who uses it. The fact that Google uses Python didn't impact my decision to start using it, and it also didn't impact my decision to start using Haskell. How much traffic they handle? How hard are to maintain/update/develope/? Those, of course, are pretty good questions. Personally, I only know http://hpaste.org/, based on Server: HAppS/0.8.4 Take a look at Hackage. There are quite a few other Haskell web frameworks as well: everything from the low-level FastCGI to higher-level HSP and WASH. And about HAppS, I'm not an Haskell expert, but reading the source I see that static files are server (in the HTTP server) using Data.ByteString.Lazy's hGetContents Is this ok? In what respect? The fact that something uses ByteString.Lazy.hGetContents doesn't imply a problem to me. It's a useful function. It can be used properly, or not, just as while or read() in C can be. It's not evil incarnate like sprintf() or anything :-) -- John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
John Goerzen wrote: On Thu, Jan 08, 2009 at 10:37:55PM +0100, Bardur Arantsson wrote: Don't get me wrong -- the socket support is pretty decent, but there are also some weird idiosyncrasies, for example requiring that the PortNum is specified in network byte order and lacking a function to convert host-network byte order (hton). Look at Haddock for PortNumber: newtype PortNumber Constructors PortNum Word16 Instances Enum PortNumber Eq PortNumber Integral PortNumber Num PortNumber Ord PortNumber Real PortNumber Show PortNumber Typeable PortNumber Storable PortNumber Try it in ghci: Prelude Network.Socket 15 :: PortNumber 15 Prelude Network.Socket PortNum 15 3840 Prelude Network.Socket (fromIntegral (15::Int))::PortNumber 15 So, in essence, there are *many* functions that let you do this. You should not be needing to construct PortNum by hand. Thanks. For some reason I hadn't thought to use (fromIntegral x)::PortNumber I guess I got stuck on the idea of constructing a PortNum directly and didn't think beyond that. (Maybe PortNum should really be an abstract type to force indirect construction...?) I guess the API isn't all that idiosyncratic after all :). Cheers, Bardur Arantsson ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, 8 Jan 2009, Bardur Arantsson wrote: Thanks. For some reason I hadn't thought to use (fromIntegral x)::PortNumber I guess I got stuck on the idea of constructing a PortNum directly and didn't think beyond that. (Maybe PortNum should really be an abstract type to force indirect construction...?) I also think that a Num instance for PortNumber is not a good idea. How shall (+) and (*) be defined? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Low-level networking [Haskell not ready for Foo]
John Goerzen wrote: On Thu, Jan 08, 2009 at 10:36:32AM -0700, John A. De Goes wrote: The number of applications requiring the implementation of a custom web server is an insignificant fraction of the number of applications requiring a messaging system. I don't think anyone would dispute Haskell's ability to do low-level, raw networking, of the type that few people actually need to do. It's the higher level stuff where there's a huge amount of room for improvement. I disagree on both points. Haskell has had somewhat of a deficit in the low-level networking stuff, not even supporting IPv6 in the standard stack until just recently. (That is, things like AF_INET6 were not present.) I think it has pretty much caught up by now though. Any idea how I get Haskell to send ICMP ECHO packets? (And, obviously, receive the replies.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
Excerpts from John A. De Goes's message of Thu Jan 08 12:14:18 -0600 2009: But really, what's the point? FFI code is fragile, often uncompilable and unsupported, and doesn't observe the idioms of Haskell nor take advantage of its powerful language features. This is a completely unfair generalization. The FFI is an excellent way to interoperate with an extraordinary amount of external libraries, and if you ask me, it's *worth* taking those pieces of C code and wrapping them up in a nice, safe haskell interface. I will also mention that Haskell has *the* simplest FFI I have ever used, which to me only means it's easier to get it right (the fact that there are customized *languages* like e.g. cython to make writing python extensions easier makes me wonder.) I suggest you take a look at the haskell llvm bindings - they are extraordinarily well documented, and the high level interface uses *many* haskell idioms that make the library safe and easy to use: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/llvm-0.4.2.0 This code most certainly takes advantage of powerful features and idioms that only Haskell can provide. Please do not take your bad experiences with a few crappy binding (or not even crappy bindings, perhaps bindings that just aren't very abstract) and extend them to the bindings that are excellent with a sweeping statement like that. Austin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
Bardur Arantsson wrote: Thanks. For some reason I hadn't thought to use (fromIntegral x)::PortNumber I guess I got stuck on the idea of constructing a PortNum directly and didn't think beyond that. (Maybe PortNum should really be an abstract No problem. I knew exactly what your problem was because I had the exact same blinders on when I first learned the Haskell networking API. It would be helpful to have a pointer to this in the Haddock docs, because it is non-intuitive to somebody just learning it. I guess the API isn't all that idiosyncratic after all :). Just a touch under-documented ;-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Hypothetical Haskell job in New York
John Goerzen wrote: On Thu, Jan 08, 2009 at 09:46:36PM +0100, Manlio Perillo wrote: I'm speaking about servers, not clients. Personally, I only know http://hpaste.org/, based on Server: HAppS/0.8.4 Take a look at Hackage. There are quite a few other Haskell web frameworks as well: everything from the low-level FastCGI to higher-level HSP and WASH. FastCGI is not a HTTP server. WASH seems so include one, but the latest version (Wash and go) seems to be from mid-2007 (tested with GHC 6.6 as the web page states), unless of course I'm looking at the wrong page. That doesn't exactly inspire a lot of confidence. Now, if you're talking about using, say, Apache + FastCGI then you'll probably have something pretty robust, but I don't think that counts as a Haskell server. Generally my experience has been that most of the Haskell server stuff hasn't been very mature. And about HAppS, I'm not an Haskell expert, but reading the source I see that static files are server (in the HTTP server) using Data.ByteString.Lazy's hGetContents Is this ok? In what respect? The fact that something uses ByteString.Lazy.hGetContents doesn't imply a problem to me. It's a useful function. It can be used properly, or not, just as while or read() in C can be. It's a great way to introduce unavoidable handle leaks, that's for sure. Cheers, Bardur Arantsson ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Low-level networking [Haskell not ready for Foo]
Andrew Coppin wrote: John Goerzen wrote: On Thu, Jan 08, 2009 at 10:36:32AM -0700, John A. De Goes wrote: The number of applications requiring the implementation of a custom web server is an insignificant fraction of the number of applications requiring a messaging system. I don't think anyone would dispute Haskell's ability to do low-level, raw networking, of the type that few people actually need to do. It's the higher level stuff where there's a huge amount of room for improvement. I disagree on both points. Haskell has had somewhat of a deficit in the low-level networking stuff, not even supporting IPv6 in the standard stack until just recently. (That is, things like AF_INET6 were not present.) I think it has pretty much caught up by now though. Any idea how I get Haskell to send ICMP ECHO packets? (And, obviously, receive the replies.) SocketType claims to support Raw, which I think is the conventional means for doing this. Whether all the infrastructure for that is there, I don't know. I have never worked with raw sockets though, so I may be leading you down a dark mugger-laden alley here ;-) -- John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 8, 2009 at 10:06 AM, Don Stewart d...@galois.com wrote: Note that there even exists an FFI binding to Erlang for Haskell, so that Haskell nodes can seamlessly interact with other nodes speaking Erlang's protocol format. Actually, the erlang package doesn't use the FFI: it speaks the Erlang wire protocol to send and receive terms. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 08, 2009 at 11:14:18AM -0700, John A. De Goes wrote: But really, what's the point? FFI code is fragile, often uncompilable and unsupported, and doesn't observe the idioms of Haskell nor take advantage of its powerful language features. Rather than coding through Just for clarity's sake, we should specify that the Erlang ffi interface that's been worked on (not my project, I've just browsed the code) is *not* low-level via C, but rather a set of parsers/ unparsers between haskell data types and the Erlang wire format and a set of behaviors for message queuing that between them let a haskell program act as a node to Erlang programs, or let Haskell programs communicate between themselves as nodes, which just coincidentally happen to use the same wire format as Erlang. Which is not to say that Erlang does not have specific excellent libraries that allow *certain types* of network programming do be done very easily. The Haskell library-space has lots of room to grow, and lots of inspiration to take from the OTP (although less for hot-swapping which is somewhat overrated, and more from supervision-tree type stuff). However, even now an adequate subset of whatever functionality is needed can be whipped up pretty quickly for any project requiring only that subset. Cheers, S. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
On Thu, Jan 8, 2009 at 1:07 PM, Manlio Perillo manlio_peri...@libero.itwrote: Another example is the multipart parser: -- | Read a multi-part message from a 'Handle'. -- Fails on parse errors. hGetMultipartBody :: String -- ^ Boundary - Handle - IO MultiPart hGetMultipartBody b h = do s - BS.hGetContents h case parseMultipartBody b s of Nothing - fail Error parsing multi-part message Just m - return m Yes, that's definitely on the scary side of things. However, you don't have to go all the way to drinking the Iteratee Kool-Aid in order to write safer networking code that is still performant. Here are a few projects I'm actively working on in this area: - I'm adding epoll support to the threaded RTS. This is a necessity for server performance. - I've added support for sending and receiving lazy ByteStrings to Johan Tibbell's network-bytestring library. A quick benchmark with a toy HTTP server has shown this to be about 2x faster than writing ByteStrings to a Handle (i.e. 14,000 requests per second, vs 7,000). - I've got a continuation-based resumable parser combinator module for attoparsec in progress, which uses lazy ByteStrings for blazing performance. You can use this to write protocol parsers in a completely clean way, decoupled from the underlying network receive operations. While much of this isn't quite ready for use yet, this just represents one person's work, and there are lots of people beavering away actively at corners of the problem space that interest them. I actually think that we're very close to being in fantastic shape here. I'm working on a memcached client library that uses the above libraries, and it's faster than the absolute best C memcached client (libmemcached), while also far smaller and elegantly layered. As a community, we are developing many proofs that you can have beautiful code without sacrificing performance. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advanced class constraints in Haskell 98?
On Thu, Jan 08, 2009 at 10:27:59PM +0100, Henning Thielemann wrote: A nice. I jumped into 4.3 and found scontext - simpleclass | (simpleclass_1, ..., simpleclass_n) simpleclass - qtycls tyvar So it must be 'atype' instead of 'tyvar'? Haskell 98 is really mighty. Oh. Don't I look silly? You were absolutely right, it's not Haskell 98. Actually Hugs does reject it without flags. Maybe you have a -98 stored somewhere? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HookedBuildInfo and Cabal
On Thu, 2009-01-08 at 12:42 -0600, John Goerzen wrote: As a more general question, how can one use Cabal to detect PostgreSQL paths in a way that works with both GHC 6.8 and 6.10? Yes: The following is using build-type: Simple in HDBC-postgresql.cabal and it does not use HDBC-postgresql.buildinfo.in or the other autoconf files. Note that I've not actually tested that this builds HDBC-postgresql fully (I don't have postgres installed). But with a suitable hacked up pgconfig/pg_config on the $PATH that it does pass the output to ghc, hsc2hs etc. It works with Cabal-1.2 and 1.6. I've not done it but you can also require a minimum pgconfig version if you modify pgconfigProgram below to discover the version number. You'd put the following in the .cabal file: build-tools: pgconfig = 7.3 or whatever. Duncan Setup.hs: import Distribution.Simple import Distribution.PackageDescription import Distribution.Version import Distribution.Simple.LocalBuildInfo import Distribution.Simple.Program import Distribution.Verbosity import Control.Monad main = defaultMainWithHooks simpleUserHooks { hookedPrograms = [pgconfigProgram], confHook = \pkg flags - do lbi - confHook defaultUserHooks pkg flags bi - psqlBuildInfo lbi return lbi { localPkgDescr = updatePackageDescription (Just bi, []) (localPkgDescr lbi) } } pgconfigProgram = (simpleProgram pgconfig) { programFindLocation = \verbosity - do pgconfig - findProgramOnPath pgconfig verbosity pg_config - findProgramOnPath pg_config verbosity return (pgconfig `mplus` pg_config) } psqlBuildInfo :: LocalBuildInfo - IO BuildInfo psqlBuildInfo lbi = do (pgconfigProg, _) - requireProgram verbosity pgconfigProgram AnyVersion (withPrograms lbi) let pgconfig = rawSystemProgramStdout verbosity pgconfigProg incDir - pgconfig [--includedir] libDir - pgconfig [--libdir] return emptyBuildInfo { extraLibDirs = [libDir], includeDirs = [incDir] } where verbosity = normal -- honestly, this is a hack ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advanced class constraints in Haskell 98?
On 9 Jan 2009, at 02:47, Ross Paterson wrote: On Thu, Jan 08, 2009 at 10:27:59PM +0100, Henning Thielemann wrote: A nice. I jumped into 4.3 and found scontext - simpleclass | (simpleclass_1, ..., simpleclass_n) simpleclass - qtycls tyvar So it must be 'atype' instead of 'tyvar'? Haskell 98 is really mighty. Oh. Don't I look silly? You were absolutely right, it's not Haskell 98. Me too. I've looked at the type declaration syntax instead of instance declaration one. Actually Hugs does reject it without flags. Maybe you have a -98 stored somewhere? ___ 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] Staged evaluation, names?
wren ng thornton schrieb: Every now and then I find myself in the position where I'd like to define some hairy value as a CAF instead of a literal, but I'd like for it to be fully evaluated at compile-time rather than postponed until runtime. It'd be possible to bludgeon the CPP into doing this, but it seems easier to use an autocannon like Template Haskell to swat this fly. Is it really necessary to use CPP or TemplateHaskell for this kind of optimization? Can a pragma help? Maybe {-# INLINE #-} ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advanced class constraints in Haskell 98?
On Fri, 9 Jan 2009, Miguel Mitrofanov wrote: On 9 Jan 2009, at 02:47, Ross Paterson wrote: On Thu, Jan 08, 2009 at 10:27:59PM +0100, Henning Thielemann wrote: A nice. I jumped into 4.3 and found scontext - simpleclass | (simpleclass_1, ..., simpleclass_n) simpleclass - qtycls tyvar So it must be 'atype' instead of 'tyvar'? Haskell 98 is really mighty. Oh. Don't I look silly? You were absolutely right, it's not Haskell 98. Me too. I've looked at the type declaration syntax instead of instance declaration one. Maybe the report is not complete? I mean, the current behaviour of Hugs and GHC (as I observed it) is more consistent, and maybe that's what the designers had in mind. Actually Hugs does reject it without flags. Maybe you have a -98 stored somewhere? When starting, my Hugs tells Haskell 98 mode: Restart with command line option -98 to enable extensions ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Staged evaluation, names?
On Thu, Jan 8, 2009 at 5:25 AM, wren ng thornton w...@freegeek.org wrote: The question for y'all is what should I call it? I've been calling the template-function qaf (for Compiled Applicative Form ;) and the type class with that function would be the only thing in the package, but I'm not sure where QAF.hs should be in the module hierarchy. Thoughts? Isn't Lift[1] already the right class for this? class Lift t where lift :: t - Q Exp [1] http://haskell.org/ghc/docs/latest/html/libraries/template-haskell/Language-Haskell-TH-Syntax.html#t%3ALift ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell not ready for Foo [was: Re: Hypothetical Haskell job in New York]
That's great to hear Bryan. I look forward to all of your projects you just mentioned, and work from others like you said, so one day soon we can built really high-performance web servers in elegant Haskell code. I also like Reactive (or FRP in general) as a declarative alternative to message passing, and hope it will be high-performance as well. Cheers, Tony 2009/1/8 Bryan O'Sullivan b...@serpentine.com On Thu, Jan 8, 2009 at 1:07 PM, Manlio Perillo manlio_peri...@libero.itwrote: Another example is the multipart parser: -- | Read a multi-part message from a 'Handle'. -- Fails on parse errors. hGetMultipartBody :: String -- ^ Boundary - Handle - IO MultiPart hGetMultipartBody b h = do s - BS.hGetContents h case parseMultipartBody b s of Nothing - fail Error parsing multi-part message Just m - return m Yes, that's definitely on the scary side of things. However, you don't have to go all the way to drinking the Iteratee Kool-Aid in order to write safer networking code that is still performant. Here are a few projects I'm actively working on in this area: - I'm adding epoll support to the threaded RTS. This is a necessity for server performance. - I've added support for sending and receiving lazy ByteStrings to Johan Tibbell's network-bytestring library. A quick benchmark with a toy HTTP server has shown this to be about 2x faster than writing ByteStrings to a Handle (i.e. 14,000 requests per second, vs 7,000). - I've got a continuation-based resumable parser combinator module for attoparsec in progress, which uses lazy ByteStrings for blazing performance. You can use this to write protocol parsers in a completely clean way, decoupled from the underlying network receive operations. While much of this isn't quite ready for use yet, this just represents one person's work, and there are lots of people beavering away actively at corners of the problem space that interest them. I actually think that we're very close to being in fantastic shape here. I'm working on a memcached client library that uses the above libraries, and it's faster than the absolute best C memcached client (libmemcached), while also far smaller and elegantly layered. As a community, we are developing many proofs that you can have beautiful code without sacrificing performance. ___ 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] Taking Exception to Exceptions
Immanuel Litzroth schrieb: Anyway, there is one more problem I have related to exceptions that is about forcing strictness. It relates to option parsing. I have an option -t that says which track from a file of tracks to print. So I go data Flags = TrackNumber !Int deriving(Read, Show, Eq) makeTrackNumber :: String - Flags makeTrackNumber str = TrackNumber $ read str options = [GetOpt.Option ['t'] [tracknumber] (GetOpt.ReqArg makeTrackNumber tracknumber) number of track to show] Now my main goes main = do args - getArgs opts - evaluate $ GetOpt.getOpt GetOpt.RequireOrder options args print done getting the opts case opts of ... which of course first prints done getting opts and then throws an exception if I give it a flag -t abc. 'evaluate' is strange here. Is it ok to put the print after the case ? But I have probably still not understood the problem. Let me point to two other issues: An elegant way to use GetOpt is: http://www.haskell.org/haskellwiki/High-level_option_handling_with_GetOpt I find it bad style to hide the exceptions, that can be raised. The type of an action should reflect what exceptions are to be expected. You can achieve this with Control.Monad.Exception.Synchronous from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/explicit-exception or Control.Monad.Error from http://hackage.haskell.org/cgi-bin/hackage-scripts/package/transformers For an application, using these techniques, see: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/equal-files ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] advanced class constraints in Haskell 98?
On Fri, Jan 09, 2009 at 01:11:12AM +0100, Henning Thielemann wrote: Maybe the report is not complete? I mean, the current behaviour of Hugs and GHC (as I observed it) is more consistent, and maybe that's what the designers had in mind. I'm puzzled by the Hugs behaviour. The current version rejects it, and I downloaded and built the Mar2005 version just to check, and it also rejected it, saying Illegal Haskell 98 class constraint in class declaration I think the GHC behaviour is connected with GHC's deferred context reduction, which also does not conform to Haskell 98. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Low-level networking [Haskell not ready for Foo]
Not all the data structures you need are there last I looked. As you could infer from my recent posts, one of my dozen future projects is to add netinet/*.h like data structures to the Haskell network library (i.e. TCP, IPv4, UDP headers with Binary instances). This isn't to say your task would be much more difficult, but it would be nice to have a community wide definition available. Tom On Thu, Jan 8, 2009 at 10:50 PM, John Goerzen jgoer...@complete.org wrote: Andrew Coppin wrote: John Goerzen wrote: On Thu, Jan 08, 2009 at 10:36:32AM -0700, John A. De Goes wrote: The number of applications requiring the implementation of a custom web server is an insignificant fraction of the number of applications requiring a messaging system. I don't think anyone would dispute Haskell's ability to do low-level, raw networking, of the type that few people actually need to do. It's the higher level stuff where there's a huge amount of room for improvement. I disagree on both points. Haskell has had somewhat of a deficit in the low-level networking stuff, not even supporting IPv6 in the standard stack until just recently. (That is, things like AF_INET6 were not present.) I think it has pretty much caught up by now though. Any idea how I get Haskell to send ICMP ECHO packets? (And, obviously, receive the replies.) SocketType claims to support Raw, which I think is the conventional means for doing this. Whether all the infrastructure for that is there, I don't know. I have never worked with raw sockets though, so I may be leading you down a dark mugger-laden alley here ;-) -- John ___ 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] advanced class constraints in Haskell 98?
On Fri, 9 Jan 2009, Ross Paterson wrote: On Fri, Jan 09, 2009 at 01:11:12AM +0100, Henning Thielemann wrote: Maybe the report is not complete? I mean, the current behaviour of Hugs and GHC (as I observed it) is more consistent, and maybe that's what the designers had in mind. I'm puzzled by the Hugs behaviour. The current version rejects it, and I downloaded and built the Mar2005 version just to check, and it also rejected it, saying Illegal Haskell 98 class constraint in class declaration You are right. I don't know, what I made different before. Btw. 2005 was the copyright year, Hugs' version is September 2006: __ __ __ __ ___ _ || || || || || || ||__ Hugs 98: Based on the Haskell 98 standard ||___|| ||__|| ||__|| __|| Copyright (c) 1994-2005 ||---|| ___|| World Wide Web: http://haskell.org/hugs || || Bugs: http://hackage.haskell.org/trac/hugs || || Version: September 2006 _ Haskell 98 mode: Restart with command line option -98 to enable extensions ERROR src/Data/Spreadsheet/CharSource.hs:14 - Illegal Haskell 98 class constraint in class declaration *** Constraint : Monad (a Maybe) *** Context: (Monad (a Maybe), Monad (a Identity)) So, since GHC allows this extension without an option - how can I tell Cabal, which extension I'm using? Has it a name anyway? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: haskell-src-exts 0.4.8
Fellow Haskelleers, it is my pleasure to announce the new release of the haskell-src-exts package, version 0.4.8: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/haskell-src-exts-0.4.8 darcs get http://code.haskell.org/HSP/haskell-src-exts This is a bug-fix release in the wake of the flurry of bug reports I received due to Neil Mitchell's release of hlint. Not all bugs have been squashed, but all the ones that I could handle with fairly small changes to the library should be. Those include deriving for MPTCs, importing constructor symbols, inline pragmas in instance declarations, scoped type variables, and a few more. There are some minor non-backwards compatible changes to the abstract syntax, but nothing too serious. The most pervasive is that the Match and PatBind constructors have an extra argument of type Maybe Type, representing an optional type signature. Derivings also are no longer just a list of class names, since those classes can now have extra parameters. Four things remain on the bug list: - Support for explicitly kinded arguments to type families. Shouldn't be too hard, but will require changes to the AST that I will leave for the next release. - Support for (un-parenthesised) higher-ranked types as arguments. haskell-src-exts supports e.g. foo :: b - (forall a . [a]) - b but not foo :: b - forall a . [a] - b. Supporting the latter is simply a parser issue, but a rather tricky one. - Correct handling of hyphened vars (an artifact of HSX/HSP) vs minus operators. This one is nasty. - Support for Unicode symbols for e.g. -. Fixing that would require me to have a Unicode-compliant editor, which it appears I don't. And I couldn't have someone else submit a patch either, since then I couldn't open the file anymore in my editor. So unless someone can point out a good Unicode-aware editor for Windows, I'm afraid this is a feature that won't be implemented. If you find anything else that haskell-src-exts fails on, please report it. Cheers and Happy Haskelling, /Niklas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Hypothetical Haskell job in New York
Well, I received 20 responses in 24 hours, many who would move from abroad to New York! I am very pleased with this number. Hopefully this will ease my boss's concern. But please continue to reply to me if you would be interested and haven't done so yet. The higher the number the more convincing the argument to my boss. Thank you to all who replied. What a great mailing list. I will let you know if it actually turns into a real job opportunity. Cheers, Tony On Wed, Jan 7, 2009 at 7:01 PM, Tony Hannan tonyhann...@gmail.com wrote: Hello Haskellers, I'm trying to convince my boss to use Haskell. His main concern is finding people who know Haskell when hiring. He is comfortable with Java because he knows he can always find a Java developer. So if I advertised we were looking for Haskell programmers in New York City, how many would respond? Please reply to this email if you would respond. Email me privately if you like and I will post the results to haskell-cafe later. Our company is a startup CDN ( http://en.wikipedia.org/wiki/Content_Delivery_Network) about 3 years old and doing well. You would hythothetically be one of 7 programmer who write all the software involved in a CDN including http server, dns server, monitoring, load balancing, customer and operator user interface, etc. The pay depends on experience but is good. Thanks, Tony ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: haskell-src-exts 0.4.8
On Thu, Jan 8, 2009 at 4:51 PM, Niklas Broberg niklas.brob...@gmail.com wrote: So unless someone can point out a good Unicode-aware editor for Windows, I'm afraid this is a feature that won't be implemented. A Windows port of a Unix editor? I know Vim is available on Windows. Otherwise, Notepad++ appears to have Unicode support. Cheers and Happy Haskelling, /Niklas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: State Monad - using the updated state
It sounds like you've got the monadic solution figured out, so that's good. Even though I would recommend using State (or StateT if necessary), I wanted to be sure this question was answered. ranq1List :: (Word64 - a ) - Word64 - [a] ranq1List converter state = converter newState : ranq1List converter newState where newState = ranq1Increment state One more question on this - the other concern I had with the recursive list approach was that although lazy evaluation prevents me generating numbers before I 'ask' for them, I figured that if I was going to be asking for say 10 million over the course of one simulation, that although I request them one by one, over hours or even days, at the end of the simulation I will still have a list of 10 million word64s - each of which I could throw away within minutes of asking for it. This seemed like huge memory bloat, and thus probably I was taking the wrong approach. This memory bloat is a space leak. In general they are to be avoided. GHC's garbage collection is quite efficient, so if you structure your program properly the space will be reclaimed after the values are used. Values will only be collected if they cannot be referenced from live code (just like Java, Python, C#, or other languages with GC). If you are able to structure your code like this: doSomething :: [Word64] - IO () doSomething (rand:rands) = do someIO rand otherIO rand ... if endFlag then return () else doSomething rands main = do let rands = ranq1List id 1 doSomething rands you won't have a space leak. The head of the list is used within doSomething, while only the tail is passed in the recursion. At the time of the recursive call to doSomething, the head 'rand' value is no longer accessible by any running code, so it can be GC'd. Contrast that with this version (somewhat contrived): doSomething2 :: [Word64] - Int - IO ()-- the Int is an index into the list. doSomething2 rands i = do let rand = rands !! i someIO rand otherIO rand ... if endFlag then return () else doSomething2 rands (i + 1) This version is Really Bad. Firstly the entire list is passed on each recursion. Every element remains within scope, so nothing is GC'd. That's the space leak. There's another big problem: the current random value is computed by traversing from the head of the list. As the index value grows, it takes progressively longer to traverse the list to retrieve the current value. (N.B. I haven't tested these specific examples, but I think I'm right.) Cheers, John Lato ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Blitting one IOUArray into another
You can't safely convert an IOUArray into a Ptr; Ptr is a raw value which isn't noticed by the garbage collector, so if the data is relocated or GC'd while you have a pointer to it, further access will corrupt memory. Rather, the data inside of an IOUArray is held in a MutableByteArray#. In Data.Array.IO.Internals you can get at the newtype for IOUArray. I have some code that looks like this: import Foreign.Ptr import Data.Array.Base import Data.Array.IO.Internals import GHC.Exts import Data.Word foreign import ccall unsafe clear_bitmap :: MutableByteArray# RealWorld - Word32 - Word32 - IO () {-# INLINE unsafeGetMutableArray# #-} unsafeGetMutableArray# :: IOUArray Int Word32 - MutableByteArray# RealWorld unsafeGetMutableArray# (IOUArray (STUArray _ _ array#)) = array# clearBitmap :: IOUArray Int Word32 - Word32 - Word32 - IO () clearBitmap a1 color size = clear_bitmap (unsafeGetMutableArray# a1) color size Then the I have a small amount of C code implementing clear_bitmap: void clear_bitmap(HsWord32* img, HsWord32 color, HsWord32 size) { for(; size; --size, ++img) { *img = color; } } This is OK to do because the unsafe ccall guarantees that no GC can happen during the outcall to clear_bitmap, so we can manipulate the pointer directly. If you want to stay entirely in Haskell, there are a bunch of operations on MutableByteArray# in GHC.Exts; see http://www.haskell.org/ghc/docs/6.10-latest/html/libraries/ghc-prim/GHC-Prim.html#12 You probably need {-# LANGUAGE MagicHash #-} in order to get these to work; it makes # be a legal symbol in identifiers. It also helps to know the newtype for IO, if you want to write actually usable functions on top of these internal bits. newtype IO a = IO (State# RealWorld - (# State# RealWorld, a #)) Of course all of this is GHC-specific, and internal to base and subject to change. But I found it useful. -- ryan On Thu, Jan 8, 2009 at 6:51 AM, Bueno, Denis denb...@sandia.gov wrote: On 01/07/2009 14:36 , Neal Alexander wqeqwe...@hotmail.com wrote: Bueno, Denis wrote: Oh, do you mean by actually calling memcpy via ffi? http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Marshal-Uti ls.html Ah, thanks. Is there a way to simply cast an IOUArray Int Int64 into something like a Ptr Int64, or will I need to change my code to allocate the arrays differently (using something in Foreign.*)? I hoogle'd functions IOUArray a b - Ptr b, but couldn't find anything. Denis ___ 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: How to give unique name/id to nodes outside any monad ?
I seem to recall reading somewhere that an object's StableName can change when it becomes evaluated; so it's possible you aren't detecting sharing because of this. You might try this instead: mkStableName' a = mkStableName $! a This forces the object to become evaluated before calling mkStableName. Of course I haven't tested this, it's just a shot in the dark. -- ryan 2009/1/8 minh thu not...@gmail.com: Interestingly, I failed to detect sharing with StableName. But using the graph node as a key turned to work... If you're interested in the experiment, see attached code. Cheers, Thu 2009/1/8 minh thu not...@gmail.com: 2009/1/8 Ertugrul Soeylemez e...@ertes.de: minh thu not...@gmail.com wrote: Nothing, simply the notation. Now, with the remark of Luke, I'm wondering how bad it is to use makeStableName/hashStableName to copy the data structure in a similar one with explicit reference (that is, using pointer or keys in a map or whatever). Probably you're misusing the notation. I don't see any reason, why monadic notation should be less readable. Usually it's even more readable. Luke's remark is very valid. Haskell is the wrong language for imperative programming. You don't have _any_ benefit of Haskell, if you use it like C. Try to change your mind. Monads aren't evil. They are there to make your life easier. Way easier than imperative methods. Well, maybe it's is just my opinion, but I found the non-monadic code in the previous mail easier to write than the monadic one... I don't know against what you're making the compareason to say it's more readable. Although I agree using Haskell requires some change of thinking, statement like yours are a bit too much for me. I find Haskell a nice language even for imperative programming... Cheers, Thu Greets, Ertugrul. Thank you, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Look at http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-StableName.html. But what's wrong with constructing the graph in a monad? On Thu, Jan 8, 2009 at 9:53 AM, minh thu not...@gmail.com wrote: Well, the processing of the data structure has to be done in the IO monad. What is the library you talk about ? Could it give the stable names (in IO) for each node of the mentioned graph (I mean, after the graph has been constructed purely) ? Thanks, Thu 2009/1/8 Lennart Augustsson lenn...@augustsson.net: Of course you don't need a monad, but you need to do the same operations as you would with a state monad to number the nodes. This is the only way in (pure) Haskell. There is no object identity in Haskell, so if you want the nodes to have identity you need to provide it. GHC does have a library for stable names which (in the IO monad) allows you to get something akin to the address of a value in memory. But that's not the functional way of doing this. -- Lennart On Thu, Jan 8, 2009 at 9:28 AM, minh thu not...@gmail.com wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. but I want to be able to discover any sharing. Thus, in b = B a a where a = A [C], if I want to malloc a similar data structure, I have to handle to the node representing B two times the same pointer (the one returned after allocating A [C]). To discover sharing, I thought it would be necessary to give unique name to node and then compare them while traversing the graph. I could give the name by hand but it would be cumbersome. But at least it would not require any monad for the bookkeeping of ungiven names. Is it possible to give those names automatically but outside any monad ? Thanks, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- nightmare = unsafePerformIO (getWrongWife = sex) http://blog.ertes.de/ ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Monads aren't evil
Ertugrul Soeylemez wrote: Hello fellow Haskellers, When I read questions from Haskell beginners, it somehow seems like they try to avoid monads and view them as a last resort, if there is no easy non-monadic way. I'm really sure that the cause for this is that most tutorials deal with monads very sparingly and mostly in the context of input/output. Also usually monads are associated with the do-notation, which makes them appear even more special, although there is really nothing special about them. Yea, i was the same way when i started learning Haskell. I understood how Monads worked, and what the motivation was for them, but not why i would want to restructure code to use them in specific instances. Why should i care about monads when i can use Arrows or (.) was also a factor. Its kinda like getting advice from an adult as a child. You have no particular reason to distrust the advice, but the value of it doesn't set in until something happens to you first hand to verify it. For me the turning point was writing some code that needed to handle running code locally/remotely in a transparent manner. Maybe having a list of real-world usage scenarios or exercises on the wiki may help. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to give unique name/id to nodes outside any monad ?
On Thu, 08 Jan 2009 21:28:27 minh thu wrote: Hi, I'd like to process some kind of graph data structure, say something like data DS = A [DS] | B DS DS | C. Graphs in funtional languages aren't usually represented in this sort of manner. Trees are fine to represent like that as they're acyclic and have exactly one parent for each node but for graphs it's much more difficult. Say that you have a graph with directed connections like this: 0 - 1 1 - 2 2 - 3 1 - 3 3 - 4 Now you want to alter node 4. Node 3 has to be updated to point to the new version of 4, node 1 has to be changed to point to the new version of 3, node 2 has to be changed to point to the new version of node 3, then node 1 has to be changed again to point to the new version of 2, then finally 0 can be changed to point to the new version of 1 and returned. There is no simple way using this representation to handle that double-update to node 1, or to handle disconnected or cyclic graphs. Updates are extremely difficult since Haskell data structures are not mutable and have no concept of identity. The approach of treating nodes as structures with pointers to each other cannot be cleanly and efficiently implemented in an immutable fashion. It only really makes sense in a stateful, imperative context. An approach that suits functional languages better is to store a flat structure listing the edges leaving each node. This, I believe, is the approach taken by Haskell's main graph library, FGL (http://hackage.haskell.org/cgi-bin/hackage-scripts/package/fgl). You would now have something like: data MyNode nv = MyNode {nodeId::Int, nodeValue::nv} data MyEdge ev = MyEdge {edgeDestination::Int, edgeValue::ev} data MyGraph nv ev = MyGraph { maxNode :: Int, nodes :: (Map Int nv), edges :: (Map Int [MyEdge ev])} emptyGraph :: MyGraph nv ev emptyGraph = MyGraph 0 (Data.Map.empty) (Data.Map.empty) getNode :: MyGraph nv ev - Int - Maybe (MyNode nv) getNode g id = ((nodes g) `lookup` id) = (\v - MyNode id v) getEdgesLeaving :: MyGraph nv ev - Int - [MyEdge ev] getEdgesLeaving g id = fromMaybe [] ((edges g) `lookup` id) addNode :: nv - MyGraph nv ev - (Int, MyGraph nv ev) addNode val g = (maxNode newGraph, newGraph) where newNodeId = (maxNode g) + 1 newGraph = MyGraph newNodeId (insert newNodeId val (nodes g)) (edges g) ... and so on. (This is all totally untested - use at your own peril.) Each node in the graph has a unique identifying number, issued in sequence using maxNode as a counter. This makes identifying cycles easy. The nodes map contains the value for each node based on its id. The edges map contains a list of links from each node to others in the graph. Finding links entering a node is quite expensive - if you need to do this often then maintaining a second list of edges entering each node would speed it up. Each node and each edge can have a custom data structure attached. New nodes and edges can be added without having to modify references elsewhere, nodes have a distinct identity given by the associated Int and the graph is immutable - operations on it produce modified copies. Cheers, Tim ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell] Re: [Haskell-cafe] ANNOUNCE: haskell-src-exts 0.4.8
Hello Max, Friday, January 9, 2009, 4:15:48 AM, you wrote: Otherwise, Notepad++ appears to have Unicode support. even notepad (on my vista box) supports utf-8, utf16be and utf16le :))) -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe