Re: [Haskell-cafe] converting prefixes of CString - String

2011-04-26 Thread Eric Stansifer
Let 'c2h' convert CStrings to Haskell Strings, and 'h2c' convert Haskell Strings to CStrings.  (If I understand correctly, c2h . h2c === id, but h2c . c2h is not the identity on all inputs; That is correct.  CStrings are 8-bits, and Haskell Strings are 32-bits.   Converting from Haskell to C

[Haskell-cafe] converting prefixes of CString - String

2011-04-25 Thread Eric Stansifer
I have been reading Foreign.C.String but it does not seem to provide the functionality I was looking for. Let 'c2h' convert CStrings to Haskell Strings, and 'h2c' convert Haskell Strings to CStrings. (If I understand correctly, c2h . h2c === id, but h2c . c2h is not the identity on all inputs;

[Haskell-cafe] thread safety, IO arrays, and IO refs

2010-12-31 Thread Eric Stansifer
Hello, I wish to use a mutable array in multiple threads. Can IO arrays be used in any thread, or only the thread they are created in? (So if I create an IO array in one thread, pass it to another via an MVar, can I read / edit it in that other thread?) Similarly about IORefs... can they be

Re: [Haskell-cafe] thread safety, IO arrays, and IO refs

2010-12-31 Thread Eric Stansifer
I tried a quick test with an IOArray, so I know that at least one time it works. I don't know enough of the internals of IO and IOArray to be able to extrapolate; there could be some race condition hidden internally if IO is misused. Thanks, Eric ___

Re: [Haskell-cafe] Not in scope: type constructor or class `Map'

2010-12-30 Thread Eric Stansifer
Because Data.Map is imported qualified, any symbols in it (including Map) needs to be qualified: type Bindings = Map.Map String Int A standard idiom is to do import like so: import qualified Data.Map as Map import Map (Map) so that the Map symbol itself does not need qualification. Eric

[Haskell-cafe] SampleVar semantics, documentation vs. source

2010-12-29 Thread Eric Stansifer
Hi, doc:   http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.0.0/Control-Concurrent-SampleVar.html source:   http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.0.0/src/Control-Concurrent-SampleVar.html The documentation for Control.Concurrent.SampleVar implies

[Haskell-cafe] lhs syntax highlighting in vim

2008-06-10 Thread Eric Stansifer
Hello, The syntax highlighting file for literate haskell in vim says that its maintainer is haskell-cafe@haskell.org, so hopefully one of you will find this relevant. In literate haskell files, vim optionally highlights the non-code text according to TeX markup. The syntax highlighting file

Re: [Haskell-cafe] Newbie: State monad example questions

2008-05-22 Thread Eric Stansifer
So, are there any other simple motivating examples that show what state is really good for? Here's an example from some code that I'm (trying to) write; I am writing a DSL for the Povray Scene Description Language. This part of my program creates a `String' which holds a piece of Povray SDL

Re: [Haskell-cafe] Short circuiting and the Maybe monad

2008-05-18 Thread Eric Stansifer
Since a tree is a kind of container, yes, it should be a monad. [I'm still not really sure whether it's useful.] I have a use for the tree monad -- well, I have a use for the monadic `join' operation (but I don't use any of the monadic operations other than `return'). My program is making a

Re: [Haskell-cafe] Short circuiting and the Maybe monad

2008-05-18 Thread Eric Stansifer
I have another implementation of FreeModule which specializes S to the natural numbers: but the set of functions f :: \mathbb{N} - R are isomorphic with f :: [R] (provided we only permit infinite lists), in the same way that Dave Menendez describes how f :: Bool - a is isomorphic to f ::

Re: [Haskell-cafe] Re: Endianess

2008-05-14 Thread Eric Stansifer
So I've always wondered, if you are writing down a number being dictated (slowly) by someone else, like 234, do you write the 2, then leave space and write the 4, then go back and fill in with 3? Or do you push the 4 onto the stack until the 3 arrives, and write 34 at once. My German

[Haskell-cafe] Type unions

2008-05-10 Thread Eric Stansifer
I have been trying to write a DSL for Povray (see www.povray.org) in Haskell, using the technique of: http://okmij.org/ftp/papers/tagless-final-APLAS.pdf with some inspiration taken from http://okmij.org/ftp/Haskell/DSLSharing.hs The Povray Scene Description Language is a very declarative

Re: [Haskell-cafe] Type unions

2008-05-10 Thread Eric Stansifer
Try making a type class for the functions. That will allow you both varargs and unions. Have a look at Text.Printf. Thank you -- looking at Printf was very helpful. My syntax is much happier as a result. I also see now that I am approaching the problem from the wrong direction -- that by

Re: [Haskell-cafe] Maybe a, The Rationale

2008-05-10 Thread Eric Stansifer
IME nullable by default is one of the biggest sources of runtime crashes in high level OOP languages like C#, which is a shame because it really isn't that difficult to statically eliminate the vast majority of them, especially when you're sort of hand-waving the semantics of your language