Re: [Haskell-cafe] Set of reals...?
Thank you, I eventually tried to go with this approad, after a few people's recommendations. But, like you mentioned in your post, now I find myself needing a notion of subset relations, and since you obviously can't define equality over functions, i'm stuck again. Do you know any way around this problem, or have i hit a dead end...? stijn. On Wed, 27 Oct 2004 10:50:24 +0100, Ben Rudiak-Gould <[EMAIL PROTECTED]> wrote: > One idea that might not occur to a newcomer is to represent each set by > a function with a type like (Double -> Bool), implementing the set > membership operation. This makes set-theoretic operations easy: the > complement of s is not.s (though watch out for NaNs!), the union of s > and t is (\x -> s x || t x), and so on. Open, closed, and half-open > intervals are easy too. The big limitation of this representation is > that there's no way to inspect a set except by testing particular values > for membership, but depending on your application this may not be a problem. > > -- Ben > > ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
aha, I see. Seems like i still have a long way to go with functional programming. final question: i tried to test the code below, but it seems GHCi will only take the `isin` functions when they are defined in lambda notation (like isin = (\x -> ...)). Did you run this code too, or were you just sketching me the rough idea? Cheers for all the replies by the way, i learnt a great deal here. stijn. On Wed, 27 Oct 2004 14:09:36 +0100, Keean Schupke <[EMAIL PROTECTED]> wrote: > Well, its functional of course: > > union :: Interval -> Interval -> Interval > union i j = Interval { >isin x = isin i x || isin j x > } > > intersection :: Interval -> Interval -> Interval > intersection i j = Interval { >isin x = isin i x && isin j x > } > > Keean. > > > > > Stijn De Saeger wrote: > > >That seems like a very clean way to define the sets indeed, but how > >would you go about implementing operations like intersection, > >complement etc... on those structures? define some sort of algebra > >over the functions? or extend such sets by adding elements? hm... > >sounds interesting,. > > > >thanks, > >stijn. > > > > > >On Wed, 27 Oct 2004 11:52:54 +0100, Keean Schupke > ><[EMAIL PROTECTED]> wrote: > > > > > >>I think someone else mentioned using functions earlier, > >>rather than a datatype why not define: > >> > >>data Interval = Interval { isin :: Float -> Bool } > >> > >>Then each range becomes a function definition, for example: > >> > >>myInterval = Interval { > >> isin r > >> | r == 0.6 = True > >> | r > 0.7 && r < 1.0 = True > >> | otherwise = False > >> } > >> > >>Then you can test with: > >> > >>(isin myInterval 0.6) > >> > >>Keean > >> > >> > >> > >> > > ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: exitFailure under forkProcess
John Goerzen wrote: > I wonder what the behavior of fwrite() in this situation is. I don't > know if it ever performs buffering such that write() is never called > during a call to fwrite(). fwrite() is no different to other stdio functions in this regard. If the stream is buffered, a call to fwrite() may simply result in data being appended to the buffer; it doesn't guarantee a call to write(). -- Glynn Clements <[EMAIL PROTECTED]> ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Text.XML.HaXML.HaskellToXml DRIFT example
On Wed, Oct 27, 2004 at 03:43:30PM -0400, S. Alexander Jacobson wrote: > Oops, I just found the examples directory. > So the next question is: Is there a way to use > DRift directly from GHCI? If I have to hmake > regularly, that will get annoying fast. Drift now comes with a script called 'drift-ghc' which is used to run drift directly from GHC. just pass ghc '-pgmF drift-ghc -F' and it will do the right thing, filtering files that contain drift directives. John -- John Meacham - ârepetae.netâjohnâ ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Text.XML.HaXML.HaskellToXml DRIFT example
"S. Alexander Jacobson" <[EMAIL PROTECTED]> writes: > Oops, I just found the examples directory. > So the next question is: Is there a way to use > DRift directly from GHCI? If I have to hmake > regularly, that will get annoying fast. If you're using emacs, there's a handy 'one-button test' setup documented here: http://www.haskell.org/hawiki/HaskellMode I've been thinking about an editor-agnostic zero-button test setup, but I don't have the details worked out yet. -- Shae Matijs Erisson - Programmer - http://www.ScannedInAvian.org/ "I will, as we say in rock 'n' roll, run until the wheels come off, because I love what I do." -- David Crosby ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Text.XML.HaXML.HaskellToXml DRIFT example
Oops, I just found the examples directory. So the next question is: Is there a way to use DRift directly from GHCI? If I have to hmake regularly, that will get annoying fast. -Alex- On Wed, 27 Oct 2004, S. Alexander Jacobson wrote: > Does someone have an example of how to use DRIFT > to convert a Haskell type into XML? > > The documentation appears rather sparse... > > -Alex- > > __ > S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com > ___ > Haskell-Cafe mailing list > [EMAIL PROTECTED] > http://www.haskell.org/mailman/listinfo/haskell-cafe > __ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Text.XML.HaXML.HaskellToXml DRIFT example
Does someone have an example of how to use DRIFT to convert a Haskell type into XML? The documentation appears rather sparse... -Alex- __ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: exitFailure under forkProcess
On Wed, Oct 27, 2004 at 11:30:12AM +0100, Simon Marlow wrote: > The System.Posix library is severely lacking in documentation. Ideally > for each function it would list the POSIX equivalent, and a table with > the mapping in the other direction would be useful too. One idea on this topic: Many POSIX wrappers, eg getProcessStatus[1], take mysterious Boolean arguments. I commonly create a new type when I have a function like this, so it might be data Blocking = Blocking | NonBlocking data IncludeStopped = IncludeStopped | ExcludeStopped getProcessStatus :: Blocking -> IncludeStopped -> ProcessID -> IO (Maybe ProcessStatus) Would this make these functions easier to use, or would it just be an additional annoyance to have to look up the values of these type? (I may have picked an extreme example, because even someone who knows POSIX by heart couldn't be sure which Boolean is which!) Andrew [1] http://haskell.org/ghc/docs/latest/html/libraries/unix/System.Posix.Process.html#v%3AgetProcessStatus ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: exitFailure under forkProcess
John Goerzen <[EMAIL PROTECTED]> writes: > I wonder what the behavior of fwrite() in this situation is. I don't > know if it ever performs buffering such that write() is never called > during a call to fwrite(). On Linux it duplicates unflushed output (hmm, I thought they fixed this a few years ago). X/Open specification doesn't say anything about this. #include #include int main() { printf("1 "); fflush(stdout); printf("2 "); fork(); printf("3\n"); } Output: 1 2 3 2 3 In C you cay say fflush(NULL) to flush all open output streams. -- __("< Marcin Kowalczyk \__/ [EMAIL PROTECTED] ^^ http://qrnik.knm.org.pl/~qrczak/ ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: exitFailure under forkProcess
On 2004-10-27, Glynn Clements <[EMAIL PROTECTED]> wrote: > One major issue is the way in which fork() has global consequences. > > E.g. if a library has file descriptors for internal use, fork() will > duplicate them. If the library subsequently closes its copy of the > descriptor, but the inherited copy (which the child may not even know > exists) remains open, the file (socket, device, etc) will remain open. This is not a novel problem with Haskell, but it certainly bears remembering. > Another example of this is the interaction between buffered streams > and descriptors. If a process forks while "unflushed" data remains in > a stream, the data may be written twice. This can be quite serious if > the stream corresponds to some form of control channel (i.e. a pipe or > socket communicating with another process). And this *is* a novel problem I hadn't thought of before. It's quite possible this has been causing some of my troubles. I would think that createProcess should automatically flush all open handles before it does the fork, and that it should probably be considered a bug if it doesn't. If it does, then the exec stuff should too. If it doesn't, then the exec stuff must not. (If the exec stuff did but forkProcess didn't, it would break the idiom of fork() then exec() that happens to work now because the exec() discards all those buffers.) I wonder what the behavior of fwrite() in this situation is. I don't know if it ever performs buffering such that write() is never called during a call to fwrite(). I also wonder if the forkIO and friends suffer from the same problem. > Ultimately, the only real solution to such issues is to ensure that > any high-level functionality provides a sufficient level of > cooperation with lower-level code, e.g. allowing it to be > "synchronised", or at least shut down into a state such that it > doesn't interfere, ensuring that it doesn't hide "unnecessary" details > which may actually be necessary in more involved programs, etc. Yup. -- John ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
Stijn De Saeger wrote: > Thanks for the explanation, at first it seemed like enumFromThenTo > would indeed give me the functionality I am looking for. But then all > of GHCi started acting weird while playing around... this is a > copy-paste transcript from the terminal. > > *S3> 0.5 `elem` [0.0,0.1..1.0] > True > *S3> 0.8 `elem` [0.6,0.7..1.0] > False > *S3> 0.8 `elem` [0.6,0.7..1.0] > False > *S3> [0.6,0.7..0.9] > [0.6,0.7,0.7999,0.8999] > *S3> > > Floating point has limited precision, and uses binary rather than decimal, so you can't exactly represent multiples of 1/10 as floating-point values. Internally, the elements of the list would actually be out by a relative error of ~2e-16 for double-precision, ~1e-7 for single precision, but the code which converts to decimal representation for printing rounds it. However, Haskell does support rationals: Prelude> [6/10 :: Rational,7/10..9/10] [3 % 5,7 % 10,4 % 5,9 % 10] Prelude> 4/5 `elem` [6/10 :: Rational,7/10..9/10] True > in your reply you wrote : > > However, you can't specify infinitesimally small steps, nor increment > > according to the resolution of the floating point type (at least, not > > using the enumeration syntax; you *could* do it manually using integer > > enumerations and encodeFloat, but that wouldn't be particularly > > practical). > > Is this what you were referring to? i wouldn't say 0.1 is an > infinitesimal small step. No; you could realistically use much smaller steps than that. My point was that you can't realistically use sufficiently small steps that values won't "fall through the cracks": Prelude> 0.61 `elem` [0.6,0.7..0.9] False Whilst you could, without too much effort, enumerate a range of floating-point values such that all intermediate values were included, the resulting list would be massive. Single precision floating-point uses a 24-bit mantissa, so an exhaustive iteration of the range [0.5..1.0] would have 2^24+1 elements. -- Glynn Clements <[EMAIL PROTECTED]> ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
Well, its functional of course: union :: Interval -> Interval -> Interval union i j = Interval { isin x = isin i x || isin j x } intersection :: Interval -> Interval -> Interval intersection i j = Interval { isin x = isin i x && isin j x } Keean. Stijn De Saeger wrote: That seems like a very clean way to define the sets indeed, but how would you go about implementing operations like intersection, complement etc... on those structures? define some sort of algebra over the functions? or extend such sets by adding elements? hm... sounds interesting,. thanks, stijn. On Wed, 27 Oct 2004 11:52:54 +0100, Keean Schupke <[EMAIL PROTECTED]> wrote: I think someone else mentioned using functions earlier, rather than a datatype why not define: data Interval = Interval { isin :: Float -> Bool } Then each range becomes a function definition, for example: myInterval = Interval { isin r | r == 0.6 = True | r > 0.7 && r < 1.0 = True | otherwise = False } Then you can test with: (isin myInterval 0.6) Keean ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
This has already been mostly answered by Ben's post, but to rephrase this, basically you do intersection by producing the function which returns the AND of the two functions given, and union by producing the function which gives the OR of the two functions given. Complement is just logical NOT. Basically, any set operation you want turns into a logical operation using as information just a single arbitrary point, and the two (or more) predicates given. You can also do arithmetic on the sets by modifying the incoming point in a suitable way before passing it on to the predicate. - Cale On Wed, 27 Oct 2004 21:36:55 +0900, Stijn De Saeger <[EMAIL PROTECTED]> wrote: > That seems like a very clean way to define the sets indeed, but how > would you go about implementing operations like intersection, > complement etc... on those structures? define some sort of algebra > over the functions? or extend such sets by adding elements? hm... > sounds interesting,. > > thanks, > stijn. > > On Wed, 27 Oct 2004 11:52:54 +0100, Keean Schupke > > > <[EMAIL PROTECTED]> wrote: > > I think someone else mentioned using functions earlier, > > rather than a datatype why not define: > > > > data Interval = Interval { isin :: Float -> Bool } > > > > Then each range becomes a function definition, for example: > > > > myInterval = Interval { > >isin r > > | r == 0.6 = True > > | r > 0.7 && r < 1.0 = True > > | otherwise = False > >} > > > > Then you can test with: > > > > (isin myInterval 0.6) > > > > Keean > > > > > ___ > Haskell-Cafe mailing list > [EMAIL PROTECTED] > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Re: exitFailure under forkProcess
Simon Marlow wrote: > > Yes. Its POSIX interface is, uhm, weird. I can't quite put my finger > > on it, but things like setting up a pipe to a child process's stdin > > just seem brittle and fragile with all sorts of weird errors. I can > > do this in my sleep in C, Perl, or Python but in Haskell I can barely > > make it work when I'm fully conscious :-) > > *laughs* > > Is there anything concrete we can do? The POSIX layer is supposed to be > pretty minimal, so in theory most POSIX idioms should not be harder in > Haskell, and hopefully should be easier. Part of the problem is that you can't always consider the use of individual POSIX functions in isolation. Things which are done (possibly unknowingly) in one place might affect the way in which other system calls behave. One major issue is the way in which fork() has global consequences. E.g. if a library has file descriptors for internal use, fork() will duplicate them. If the library subsequently closes its copy of the descriptor, but the inherited copy (which the child may not even know exists) remains open, the file (socket, device, etc) will remain open. Another example of this is the interaction between buffered streams and descriptors. If a process forks while "unflushed" data remains in a stream, the data may be written twice. This can be quite serious if the stream corresponds to some form of control channel (i.e. a pipe or socket communicating with another process). Ultimately, the only real solution to such issues is to ensure that any high-level functionality provides a sufficient level of cooperation with lower-level code, e.g. allowing it to be "synchronised", or at least shut down into a state such that it doesn't interfere, ensuring that it doesn't hide "unnecessary" details which may actually be necessary in more involved programs, etc. -- Glynn Clements <[EMAIL PROTECTED]> ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ArrowLoop examples?
On Sat, Oct 23, 2004 at 08:55:16PM +0300, Einar Karttunen wrote: > Are there any examples of using ArrowLoop outside the signal > functions? Instances are declared for ordinary functions and > Kleisli arrows, but how should they be actually used? You wouldn't normally use those instances directly. With ordinary functions, you can just use recursion; with monads you can use Control.Monad.Fix.mfix (or monadic do-notation, which reduces to the same thing). Using loop for such arrows would be equivalent, but more awkward. Most of the useful examples seen so far in "proper arrows" have been in the different kinds of signal processors. Another example might be plumbing of attributes in a parsing arrow (though the loop in this case doesn't satisfy right tightening), where you want to pass values of later symbols to the parsers for earlier ones. With a monadic parser you'd do this using with mfix; with an arrow-based one, you'd use loop. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
That seems like a very clean way to define the sets indeed, but how would you go about implementing operations like intersection, complement etc... on those structures? define some sort of algebra over the functions? or extend such sets by adding elements? hm... sounds interesting,. thanks, stijn. On Wed, 27 Oct 2004 11:52:54 +0100, Keean Schupke <[EMAIL PROTECTED]> wrote: > I think someone else mentioned using functions earlier, > rather than a datatype why not define: > > data Interval = Interval { isin :: Float -> Bool } > > Then each range becomes a function definition, for example: > > myInterval = Interval { >isin r > | r == 0.6 = True > | r > 0.7 && r < 1.0 = True > | otherwise = False >} > > Then you can test with: > > (isin myInterval 0.6) > > Keean > > ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
I think someone else mentioned using functions earlier, rather than a datatype why not define: data Interval = Interval { isin :: Float -> Bool } Then each range becomes a function definition, for example: myInterval = Interval { isin r | r == 0.6 = True | r > 0.7 && r < 1.0 = True | otherwise = False } Then you can test with: (isin myInterval 0.6) Keean ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] exitFailure under forkProcess
On 26 October 2004 22:29, John Goerzen wrote: > Hello, > > I'm having a little weird situation here. > > Whenever I call exitFailure under forkProcess, I get: > > (progname): forkProcess: uncaught exception > > Test program: > > import System.Exit > import System.Posix.Process > main = forkProcess exitFailure That's a bug, and I've just fixed it. The problem was that we weren't wrapping the child process in the usual default exception handler which catches ExitException and actually performs the exit. Cheers, Simon ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
On 2004-10-27 at 19:37+0900 Stijn De Saeger wrote: > hello > > Thanks for the explanation, at first it seemed like enumFromThenTo > would indeed give me the functionality I am looking for. But then all > of GHCi started acting weird while playing around... this is a > copy-paste transcript from the terminal. > > *S3> 0.5 `elem` [0.0,0.1..1.0] > True > *S3> 0.8 `elem` [0.6,0.7..1.0] > False > *S3> 0.8 `elem` [0.6,0.7..1.0] > False > *S3> [0.6,0.7..0.9] > [0.6,0.7,0.7999,0.8999] > *S3> > > > why would the floating point step size work the first time but not the > second? confusing... Doubles aren't real numbers, they're binary floating point. 1/5 doesn't have a finite binary representation. Also what gets printed out has been converted back to decimal and rounded a bit. So don't expect too much from them! You probably want to use Double -> Bool, and possibly look at infinite precision real arithmetic too. Jón -- Jón Fairbairn [EMAIL PROTECTED] ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Re: exitFailure under forkProcess
On 27 October 2004 02:03, John Goerzen wrote: > On 2004-10-26, Peter Simons <[EMAIL PROTECTED]> wrote: >> By the way: It's good to know I'm not the only one wrestling >> with Haskell's concurrency code. :-) > > Yes. Its POSIX interface is, uhm, weird. I can't quite put my finger > on it, but things like setting up a pipe to a child process's stdin > just seem brittle and fragile with all sorts of weird errors. I can > do this in my sleep in C, Perl, or Python but in Haskell I can barely > make it work when I'm fully conscious :-) *laughs* Is there anything concrete we can do? The POSIX layer is supposed to be pretty minimal, so in theory most POSIX idioms should not be harder in Haskell, and hopefully should be easier. We're open to suggestions, and even more open to code... > Oh also, I would very much appreciate Haskell interfaces to realpath() > and readlink(). And a system/rawSystem that returns the waitpid() > exit status like system(3) does, not just the exit code. (What > happens if the process died because of a signal?) system(3) is one of the things missing from the current System.Posix API. To see what else we consider to be missing, take a look at the comment in the System.Posix source: http://cvs.haskell.org/cgi-bin/cvsweb.cgi/~checkout~/fptools/libraries/u nix/System/Posix.hs?rev=1.11;content-type=text%2Fplain Since realpath() isn't POSIX, it would have to go into System.Posix.Exts. Cheers, Simon ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
hello Thanks for the explanation, at first it seemed like enumFromThenTo would indeed give me the functionality I am looking for. But then all of GHCi started acting weird while playing around... this is a copy-paste transcript from the terminal. *S3> 0.5 `elem` [0.0,0.1..1.0] True *S3> 0.8 `elem` [0.6,0.7..1.0] False *S3> 0.8 `elem` [0.6,0.7..1.0] False *S3> [0.6,0.7..0.9] [0.6,0.7,0.7999,0.8999] *S3> in your reply you wrote : > However, you can't specify infinitesimally small steps, nor increment > according to the resolution of the floating point type (at least, not > using the enumeration syntax; you *could* do it manually using integer > enumerations and encodeFloat, but that wouldn't be particularly > practical). Is this what you were referring to? i wouldn't say 0.1 is an infinitesimal small step. why would the floating point step size work the first time but not the second? confusing... thanks for the help though, much appreciated. stijn. On Wed, 27 Oct 2004 10:31:28 +0100, Glynn Clements <[EMAIL PROTECTED]> wrote: > > Stijn De Saeger wrote: > > > I'm new to this list, as well as to haskell, so this question probably > > has "newbie" written all over it. > > I'm thinking of a way to represent a set of reals, say the reals > > between 0.0 and 1.0. Right now I am just using a pair of Float to > > represent the lower and upper bounds of the set, but i have this dark > > throbbing feeling that there should be a more haskellish way to do > > this, using laziness. > > List comprehensions are out it seems, because they increment with > > integer steps... (obviously). In other words, 0.5 `inSet` (Set > > [0.0..1.0]) returns False. > > That form ([0.0..1.0]) is syntactic sugar for enumFromTo. There's also > enumFromThenTo, for which you can use the syntax: > > [0.0,0.1..1.0] > > However, you can't specify infinitesimally small steps, nor increment > according to the resolution of the floating point type (at least, not > using the enumeration syntax; you *could* do it manually using integer > enumerations and encodeFloat, but that wouldn't be particularly > practical). > > The only practical way to deal with large sets of reals is to use your > own representation and write your own operators on it (or hope that > someone else has written such a library). Generating massive lists (or > other structures) then testing for membership won't result in the > lists being optimised away. > > -- > Glynn Clements <[EMAIL PROTECTED]> > ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Re: exitFailure under forkProcess
On 27 October 2004 10:13, Glynn Clements wrote: > John Goerzen wrote: > >> Oh also, I would very much appreciate Haskell interfaces to >> realpath() and readlink(). > > I don't know about realpath() (which is a BSD-ism, and included in GNU > libc, but I'm not sure about other Unices), but readlink() exists as > System.Posix.readSymbolicLink. The System.Posix library is severely lacking in documentation. Ideally for each function it would list the POSIX equivalent, and a table with the mapping in the other direction would be useful too. Cheers, Simon ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
One idea that might not occur to a newcomer is to represent each set by a function with a type like (Double -> Bool), implementing the set membership operation. This makes set-theoretic operations easy: the complement of s is not.s (though watch out for NaNs!), the union of s and t is (\x -> s x || t x), and so on. Open, closed, and half-open intervals are easy too. The big limitation of this representation is that there's no way to inspect a set except by testing particular values for membership, but depending on your application this may not be a problem. -- Ben ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
Thanks for the swift reply, see inline On Wed, 27 Oct 2004 09:51:29 +0100, Graham Klyne <[EMAIL PROTECTED]> wrote: > I think the first question you have to address is whether you really want > to represent a *set* of reals or an *interval* of reals. A set of intervals, I would assume... The reason for that is that i will probably end up with set theoretic operations like complement, and in that case the complement of an interval of reals will have a hole in it somewhere. That's why i represented them as lists of pairs (lower and upper bound of the sub-interval, so to speak) , but that will probably get ugly before long. > Then, some other questions follow: > - possibly infinite sets within any given interval? I was not explicitly thinking of infinite sets, i just wanted to keep the precision open for now. I would say, up to 4 decimal figures maximum. > - open or closed intervals? closed intervals, but with holes. (see above) > and probably more. > > #g > -- cheers, stijn ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
Stijn De Saeger wrote: > I'm new to this list, as well as to haskell, so this question probably > has "newbie" written all over it. > I'm thinking of a way to represent a set of reals, say the reals > between 0.0 and 1.0. Right now I am just using a pair of Float to > represent the lower and upper bounds of the set, but i have this dark > throbbing feeling that there should be a more haskellish way to do > this, using laziness. > List comprehensions are out it seems, because they increment with > integer steps... (obviously). In other words, 0.5 `inSet` (Set > [0.0..1.0]) returns False. That form ([0.0..1.0]) is syntactic sugar for enumFromTo. There's also enumFromThenTo, for which you can use the syntax: [0.0,0.1..1.0] However, you can't specify infinitesimally small steps, nor increment according to the resolution of the floating point type (at least, not using the enumeration syntax; you *could* do it manually using integer enumerations and encodeFloat, but that wouldn't be particularly practical). The only practical way to deal with large sets of reals is to use your own representation and write your own operators on it (or hope that someone else has written such a library). Generating massive lists (or other structures) then testing for membership won't result in the lists being optimised away. -- Glynn Clements <[EMAIL PROTECTED]> ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
I think the first question you have to address is whether you really want to represent a *set* of reals or an *interval* of reals. Then, some other questions follow: - possibly infinite sets within any given interval? - open or closed intervals? and probably more. #g -- At 16:56 27/10/04 +0900, Stijn De Saeger wrote: Hi all, I'm new to this list, as well as to haskell, so this question probably has "newbie" written all over it. I'm thinking of a way to represent a set of reals, say the reals between 0.0 and 1.0. Right now I am just using a pair of Float to represent the lower and upper bounds of the set, but i have this dark throbbing feeling that there should be a more haskellish way to do this, using laziness. List comprehensions are out it seems, because they increment with integer steps... (obviously). In other words, 0.5 `inSet` (Set [0.0..1.0]) returns False. I'm sure someone must have hit this problem before me and found a way around it. any suggestions greatly appreciated, regards, stijn. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe Graham Klyne For email: http://www.ninebynine.org/#Contact ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: exitFailure under forkProcess
John Goerzen wrote: > Oh also, I would very much appreciate Haskell interfaces to realpath() > and readlink(). I don't know about realpath() (which is a BSD-ism, and included in GNU libc, but I'm not sure about other Unices), but readlink() exists as System.Posix.readSymbolicLink. -- Glynn Clements <[EMAIL PROTECTED]> ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Set of reals...?
On Wed, Oct 27, 2004 at 04:56:26PM +0900, Stijn De Saeger wrote: > Hi all, > I'm new to this list, as well as to haskell, so this question probably > has "newbie" written all over it. Not really. > I'm thinking of a way to represent a set of reals, say the reals > between 0.0 and 1.0. Right now I am just using a pair of Float to > represent the lower and upper bounds of the set, but i have this dark > throbbing feeling that there should be a more haskellish way to do > this, using laziness. > List comprehensions are out it seems, because they increment with > integer steps... (obviously). In other words, 0.5 `inSet` (Set > [0.0..1.0]) returns False. Yes. That is because lists are either finite or countable, whereas any interval of the reals is uncountable. Not all is lost however. > I'm sure someone must have hit this problem before me and found a way > around it. any suggestions greatly appreciated, Well, there have been multiple forays into exact real arithmetic, with implementations in Haskell. One that may well be of use to your problem is David Plume's calculator for exact real number computation. Google for it, and for `interval arithmetic'. Doei, Arthur. -- /\/ | [EMAIL PROTECTED] | Work like you don't need the money /__\ / | A friend is someone with whom | Love like you have never been hurt /\/__ | you can dare to be yourself | Dance like there's nobody watching ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Set of reals...?
Hi all, I'm new to this list, as well as to haskell, so this question probably has "newbie" written all over it. I'm thinking of a way to represent a set of reals, say the reals between 0.0 and 1.0. Right now I am just using a pair of Float to represent the lower and upper bounds of the set, but i have this dark throbbing feeling that there should be a more haskellish way to do this, using laziness. List comprehensions are out it seems, because they increment with integer steps... (obviously). In other words, 0.5 `inSet` (Set [0.0..1.0]) returns False. I'm sure someone must have hit this problem before me and found a way around it. any suggestions greatly appreciated, regards, stijn. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe