Re: [Haskell-cafe] FFI link failing due to no main?
I'm not really sure, but does the linking step really need to be given the --make flag? I would try linking without that in the first instance. I think so - it's not just a link step, it does the following: Compile: CInterface.c - CInterface.o Link: CInterface.o HaskellFuncs_stub.o Hasnkell.Funcs.o - libCInterface.so I'll take a look at the full -v output and see if that reveals anything. Thanks, Phil. On 27 Aug 2009, at 04:38, Bernie Pope wrote: Hi Phil, ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Mapping over multiple values of a list at once?
Hi, Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? The naive ansatz to use (!!) excessively sounds pretty inefficient. Bye, Lenny ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping over multiple values of a list at once?
transpose tails, I guess. hask...@kudling.de wrote: Hi, Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? The naive ansatz to use (!!) excessively sounds pretty inefficient. Bye, Lenny ___ 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] Mapping over multiple values of a list at once?
Right. How about: f = map ((`div` 3) . sum . take 3) . tails You probably want to do filter out some of the tails. Not sure where transpose comes into play, but tails is your friend here. Martijn. Miguel Mitrofanov wrote: transpose tails, I guess. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping over multiple values of a list at once?
Not sure where transpose comes into play, My original attempt was transpose . take 3 . tails. There's more than one way to do the job... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping over multiple values of a list at once?
My first approach would be to generate the list of sliding windows: [[4,3,2],[3,2,6],[2,6,7]] after importing Data.List: map (take 3) . tails $ [4,3,2,6,7] [[4,3,2],[3,2,6],[2,6,7],[6,7],[7],[]] Not quite what we want, but close: filter ((== 3) . length) . map (take 3) . tails $ [4,3,2,6,7] [[4,3,2],[3,2,6],[2,6,7]] So (filter ((== 3) . length) . map (take 3) . tails) seems to be the desired function. Now just map average. However, we don't really need the sliding windows themselves, just the sliding sum. There might be a slightly more efficient way to do that, but I'll leave it as an exercise for you or somebody else. --Max On Thu, Aug 27, 2009 at 10:19 AM, hask...@kudling.de wrote: Hi, Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? The naive ansatz to use (!!) excessively sounds pretty inefficient. Bye, Lenny ___ 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] Mapping over multiple values of a list at once?
tails seems to be the key. I haven't thought of this before. Thanks for pointing me in the right direction, guys. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping over multiple values of a list at once?
tails seems to be the key. I haven't thought of this before. Thanks for pointing me in the right direction, guys. For a more interesting solution: http://blog.sigfpe.com/2006/12/evaluating-cellular-automata-is.html I believe you can adapt his 'rule' function to your problem. It's probably overkill, but good learning material =) Have fun! -- Ariel J. Birnbaum ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping over multiple values of a list at once?
For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? It's probably less elegant than tails, but very likely more efficient to keep track of running sums instead of summing the sublists over and over again. import Data.Ratio nsums n xs = map (% n) $ scanl (+) (sum (take n xs)) $ zipWith (-) (drop n xs) xs Gergely -- http://www.fastmail.fm - The professional email service ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping over multiple values of a list at once?
How about this one? Should be pretty efficient. let mavg n xs = let (sum - seed,rest) = splitAt n xs in map (%n) . scanl (\a (p,n) - a+n-p) seed $ xs `zip` rest 2009/8/27 Patai Gergely patai_gerg...@fastmail.fm: For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? It's probably less elegant than tails, but very likely more efficient to keep track of running sums instead of summing the sublists over and over again. import Data.Ratio nsums n xs = map (% n) $ scanl (+) (sum (take n xs)) $ zipWith (-) (drop n xs) xs Gergely -- http://www.fastmail.fm - The professional email service ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: scion 0.1
On 27 Aug 2009, at 09:17, Johan Tibell wrote: Hi Thomas, This is really cool stuff. I played with it this morning and found a potential bug. Both the emacs and vim client libraries refer to the binary scion_server but the binary that gets built and put in ~/.cabal/bin is called scion-server (note the dash). I worked around the problem by putting this in my .emacs: Right, I changed that before the release and apparently forgot to change a few places. Will be fixed in the next minor version. (setq scion-program scion-server) Also, I tried to play with the scion-open-cabal-project function. I'm not sure I understand how it's intended to be used. Does it make sure that if you compile a file using C-c C-x C-l the right source directories are used? Could you give a usage example? I eventually want to get rid of it and let scion-load figure out itself when the project needs to be reconfigured. At the moment you have to delete the .dist-scion directory if you changed your .cabal file. :/ One problem I frequently have with emacs-mode is that you can't use it to load a file if * your sources don't live in the same directory as the Cabal file, or Actually, the latest version of haskell-mode has some heuristics. It sets the working directory to where the .cabal file lives. * the file needs preprocessing (e.g. it's a .hsc) file. Now when we have the Cabal file loaded would it be possible to have Cabal compile the project and then try to load the .hs file generated from the .hsc file that is currently opened? Right, so those files should be generated, but it's quite difficult to update them automatically and recompile the necessary files. Also, some preprocessers don't add the proper {-# LINE #-} markers, so the error messages will be all wrong. So, I think it should work this way: User opens a .hsc / .y / .x file, Scion figures out that the file needs preprocessing, loads the generated file and highlights the error messages and highlights them in the original file. Thanks! -- Johan / Thomas -- Push the envelope. Watch it bend. PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping over multiple values of a list at once?
Just wondering, what should be the expected output be of something like mavg 4 [1..3]? [3%2] or []? Patai's and Eugene's solutions assume the former. On Thu, Aug 27, 2009 at 10:19 AM, hask...@kudling.de wrote: Hi, Imagine you have a list with n-values. You are asked to iterate over the list and calculate the average value of each 3 neighbouring values. For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? The naive ansatz to use (!!) excessively sounds pretty inefficient. Bye, Lenny ___ 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] Mapping over multiple values of a list at once?
Or, when the list is infinite, turn it into a some neat but cryptic State computation: avgs = (:) $ ((\d - sum d `div` 3) $ StateT (pure . splitAt 3)) * avgs test = evalState avgs [1,2..] -- Sebastiaan Visser On Aug 27, 2009, at 11:19 AM, Eugene Kirpichov wrote: How about this one? Should be pretty efficient. let mavg n xs = let (sum - seed,rest) = splitAt n xs in map (%n) . scanl (\a (p,n) - a+n-p) seed $ xs `zip` rest 2009/8/27 Patai Gergely patai_gerg...@fastmail.fm: For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? It's probably less elegant than tails, but very likely more efficient to keep track of running sums instead of summing the sublists over and over again. import Data.Ratio nsums n xs = map (% n) $ scanl (+) (sum (take n xs)) $ zipWith (-) (drop n xs) xs Gergely ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] Mapping over multiple values of a list at once?
Hello Sebastiaan, Thursday, August 27, 2009, 3:49:48 PM, you wrote: you also need to replace (\d - sum d `div` 3) with (`div` 3) . sum in order to keep Haskell spirit :) Or, when the list is infinite, turn it into a some neat but cryptic State computation: avgs = (:) $ ((\d - sum d `div` 3) $ StateT (pure . splitAt 3)) * avgs test = evalState avgs [1,2..] -- Sebastiaan Visser On Aug 27, 2009, at 11:19 AM, Eugene Kirpichov wrote: How about this one? Should be pretty efficient. let mavg n xs = let (sum - seed,rest) = splitAt n xs in map (%n) . scanl (\a (p,n) - a+n-p) seed $ xs `zip` rest 2009/8/27 Patai Gergely patai_gerg...@fastmail.fm: For example, starting from [4,3,2,6,7] you need to find the averages of 4,3,2 and 3,2,6 and 2,6,7 resulting in [3,4,5] What is the most elegant way to do that? It's probably less elegant than tails, but very likely more efficient to keep track of running sums instead of summing the sublists over and over again. import Data.Ratio nsums n xs = map (% n) $ scanl (+) (sum (take n xs)) $ zipWith (-) (drop n xs) xs Gergely ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad
Hi all, I am very pleased to announce the first release of the jail[1,2] package. A jailed IO monad that can restrict filesystem access for your code. This package will soon be an integral part of the Salvia web server. (a new and improved Salvia will be released soon) Basic documentation of the jail package is included below. Any comments, suggestions, audits, etc. are welcome! Gr, -- Sebastiaan Visser [1] Source repo: http://github.com/sebastiaanvisser/jail/ [2] Hackage: http://hackage.haskell.org/package/jail Like all of us know, the IO monad from the System.IO module is a wild beast allowing all forms of insecure computations that can read, or even worse, alter the real world. Writing to sockets, deleting files or even launching missiles, its possibilities are endless. This library provides a special IO module that wraps all file and handle based IO operations from the System.IO module, but provides a possibility to run them in an restricted environment. When running a jailed IO computation a file path can be specified all IO operations will be checked against. Accessing files outside this directory is not allowed and results in a runtime error. Additionally, when running a jailed IO computation a whitelist of file handles can be specified that are accessible as well. For example, running some code with the permission to access all files within (and only within) my home directory and allowing to access the standard output and standard error can be enforced like this: Jail.run (Just /home/sebas) [stdout, stderr] yourUntrustworthyComputation Only allowing the code to access the standard input and nothing else can be enforced like this: Jail.run Nothing [stdin] yourEvenMoreUntrustworthyComputation Because the jailed IO environment keeps track of all file handles and checks that are opened by its own operations, smuggling in evil file handles from the fierce and dangerous outside world will be punished by border patrol. Only handles from the whitelist or handles securely opened by functions like openFile will be accepted. Because of the opaque IO constructor and the restricted set of exported operations this module is not easily fooled. I would almost dare to say this module is conceptually safe and code with the jailed IO type can blindly be trusted. Except, yes unfortunately except, unsafePerformIO ruins it all. I would almost suggest adding a flag to the compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in order to be able to create systems in which code can be trusted by its type alone. Nonetheless, this module is one step forward in trusting your own programs. Some real http://tinyurl.com/paranoidpeople prefer writing there software in one of the most insecure programming languages and perform security audits by hand, I'd rather have my compiler do the job. (Anyone who wants to audit this library is more than welcome!) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad
Neat! On Thu, Aug 27, 2009 at 10:09 AM, Sebastiaan Visser sfvis...@cs.uu.nlwrote: Hi all, I am very pleased to announce the first release of the jail[1,2] package. A jailed IO monad that can restrict filesystem access for your code. This package will soon be an integral part of the Salvia web server. (a new and improved Salvia will be released soon) Basic documentation of the jail package is included below. Any comments, suggestions, audits, etc. are welcome! Gr, -- Sebastiaan Visser [1] Source repo: http://github.com/sebastiaanvisser/jail/ [2] Hackage: http://hackage.haskell.org/package/jail Like all of us know, the IO monad from the System.IO module is a wild beast allowing all forms of insecure computations that can read, or even worse, alter the real world. Writing to sockets, deleting files or even launching missiles, its possibilities are endless. This library provides a special IO module that wraps all file and handle based IO operations from the System.IO module, but provides a possibility to run them in an restricted environment. When running a jailed IO computation a file path can be specified all IO operations will be checked against. Accessing files outside this directory is not allowed and results in a runtime error. Additionally, when running a jailed IO computation a whitelist of file handles can be specified that are accessible as well. For example, running some code with the permission to access all files within (and only within) my home directory and allowing to access the standard output and standard error can be enforced like this: Jail.run (Just /home/sebas) [stdout, stderr] yourUntrustworthyComputation Only allowing the code to access the standard input and nothing else can be enforced like this: Jail.run Nothing [stdin] yourEvenMoreUntrustworthyComputation Because the jailed IO environment keeps track of all file handles and checks that are opened by its own operations, smuggling in evil file handles from the fierce and dangerous outside world will be punished by border patrol. Only handles from the whitelist or handles securely opened by functions like openFile will be accepted. Because of the opaque IO constructor and the restricted set of exported operations this module is not easily fooled. I would almost dare to say this module is conceptually safe and code with the jailed IO type can blindly be trusted. Except, yes unfortunately except, unsafePerformIO ruins it all. I would almost suggest adding a flag to the compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in order to be able to create systems in which code can be trusted by its type alone. Nonetheless, this module is one step forward in trusting your own programs. Some real http://tinyurl.com/paranoidpeople prefer writing there software in one of the most insecure programming languages and perform security audits by hand, I'd rather have my compiler do the job. (Anyone who wants to audit this library is more than welcome!) ___ 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] ANN: jail-0.0.1 - Jailed IO monad
Cool! However, it does not protect me from doing System.IO.Unsafe.unsafePerformIO in whatever fashion I like, does it? 2009/8/27 Sebastiaan Visser sfvis...@cs.uu.nl: Hi all, I am very pleased to announce the first release of the jail[1,2] package. A jailed IO monad that can restrict filesystem access for your code. This package will soon be an integral part of the Salvia web server. (a new and improved Salvia will be released soon) Basic documentation of the jail package is included below. Any comments, suggestions, audits, etc. are welcome! Gr, -- Sebastiaan Visser [1] Source repo: http://github.com/sebastiaanvisser/jail/ [2] Hackage: http://hackage.haskell.org/package/jail Like all of us know, the IO monad from the System.IO module is a wild beast allowing all forms of insecure computations that can read, or even worse, alter the real world. Writing to sockets, deleting files or even launching missiles, its possibilities are endless. This library provides a special IO module that wraps all file and handle based IO operations from the System.IO module, but provides a possibility to run them in an restricted environment. When running a jailed IO computation a file path can be specified all IO operations will be checked against. Accessing files outside this directory is not allowed and results in a runtime error. Additionally, when running a jailed IO computation a whitelist of file handles can be specified that are accessible as well. For example, running some code with the permission to access all files within (and only within) my home directory and allowing to access the standard output and standard error can be enforced like this: Jail.run (Just /home/sebas) [stdout, stderr] yourUntrustworthyComputation Only allowing the code to access the standard input and nothing else can be enforced like this: Jail.run Nothing [stdin] yourEvenMoreUntrustworthyComputation Because the jailed IO environment keeps track of all file handles and checks that are opened by its own operations, smuggling in evil file handles from the fierce and dangerous outside world will be punished by border patrol. Only handles from the whitelist or handles securely opened by functions like openFile will be accepted. Because of the opaque IO constructor and the restricted set of exported operations this module is not easily fooled. I would almost dare to say this module is conceptually safe and code with the jailed IO type can blindly be trusted. Except, yes unfortunately except, unsafePerformIO ruins it all. I would almost suggest adding a flag to the compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in order to be able to create systems in which code can be trusted by its type alone. Nonetheless, this module is one step forward in trusting your own programs. Some real http://tinyurl.com/paranoidpeople prefer writing there software in one of the most insecure programming languages and perform security audits by hand, I'd rather have my compiler do the job. (Anyone who wants to audit this library is more than welcome!) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Qualified operators
What's the syntax for using a qualified operator (I have a clash of !)? -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Qualified operators
firstArgument Cool.Module.Name.%- secondArgument Colin Paul Adams wrote: What's the syntax for using a qualified operator (I have a clash of !)? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad
On Aug 27, 2009, at 4:16 PM, Eugene Kirpichov wrote: Cool! However, it does not protect me from doing System.IO.Unsafe.unsafePerformIO in whatever fashion I like, does it? Unfortunately not, hence my disclaimer: I would almost dare to say this module is conceptually safe and code with the jailed IO type can blindly be trusted. Except, yes unfortunately except, unsafePerformIO ruins it all. I would almost suggest adding a flag to the compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in order to be able to create systems in which code can be trusted by its type alone. Hope there will once be a nice solution to this... -- Sebastiaan Visser 2009/8/27 Sebastiaan Visser sfvis...@cs.uu.nl: Hi all, I am very pleased to announce the first release of the jail[1,2] package. A jailed IO monad that can restrict filesystem access for your code. This package will soon be an integral part of the Salvia web server. (a new and improved Salvia will be released soon) Basic documentation of the jail package is included below. Any comments, suggestions, audits, etc. are welcome! Gr, -- Sebastiaan Visser [1] Source repo: http://github.com/sebastiaanvisser/jail/ [2] Hackage: http://hackage.haskell.org/package/jail ... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: jail-0.0.1 - Jailed IO monad
http://hackage.haskell.org/package/IOSpec -- ? Looks kind of promising though I must confess I've never used it. Dave On Thu, Aug 27, 2009 at 7:39 AM, Sebastiaan Visser sfvis...@cs.uu.nlwrote: On Aug 27, 2009, at 4:16 PM, Eugene Kirpichov wrote: Cool! However, it does not protect me from doing System.IO.Unsafe.unsafePerformIO in whatever fashion I like, does it? Unfortunately not, hence my disclaimer: I would almost dare to say this module is conceptually safe and code with the jailed IO type can blindly be trusted. Except, yes unfortunately except, unsafePerformIO ruins it all. I would almost suggest adding a flag to the compiler to enforce the absence ofunsafeRuinMyTypeSafety-alike functions in order to be able to create systems in which code can be trusted by its type alone. Hope there will once be a nice solution to this... -- Sebastiaan Visser 2009/8/27 Sebastiaan Visser sfvis...@cs.uu.nl: Hi all, I am very pleased to announce the first release of the jail[1,2] package. A jailed IO monad that can restrict filesystem access for your code. This package will soon be an integral part of the Salvia web server. (a new and improved Salvia will be released soon) Basic documentation of the jail package is included below. Any comments, suggestions, audits, etc. are welcome! Gr, -- Sebastiaan Visser [1] Source repo: http://github.com/sebastiaanvisser/jail/ [2] Hackage: http://hackage.haskell.org/package/jail ... ___ 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] Qualified operators
Miguel == Miguel Mitrofanov miguelim...@yandex.ru writes: Miguel firstArgument Cool.Module.Name.%- secondArgument Thanks. I think I tried that first, must have have got misled by ghc's other confusing messages. Compiling ok now. -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Applicative and Monad transformers
You could test your instance using the checkers package on hackage (has quickcheck properties for common typeclasses) to see if it fulfills the applicative laws. But I'm not sure if it is acceptable to define applicative instances that don't match the monad instance. Does anyone know of libraries that depend on applicative instances matching their corresponding monad instance? I've often wanted an applicative instance for a datatype that didn't match the monad instance. For example, I find the zipping applicative list instance more useful than the current choice applicative list instance instance Applicative [] where pure x = repeat x fs * xs = zipWith ($) fs xs This actually also has a corresponding Monad instance (with a couple restrictions). It would be nice if there was a way to hide instances so that they could be redefined. - Job On Wed, Aug 26, 2009 at 12:04 PM, Martijn van Steenbergen mart...@van.steenbergen.nl wrote: Jeremy Shaw wrote: What I would prefer is: instance (Monad f, Applicative f) = Applicative (ReaderT r f) where pure a = ReaderT $ const (pure a) f * a = ReaderT $ \r - ((runReaderT f r) * (runReaderT a r)) Right. This doesn't only go for ReaderT, it already goes for Either, too: you don't want the 'ap' implementation for * there either. These are beautiful examples of how applicative style gives the caller less power, but the callee more information, allowing more information to be retained. In this case it allows you to concatenate errors using mappend. Another example is parsing: I believe Doaitse's parsers allow more optimization if they are only used in applicative style (but I'm not sure of this). This shows there can be several sensible implementations of a type class. You ask which instance is right--that depends entirely on what you want it to do! Setting (*) = ap is just one of them, one you happen to get for free if your functor is already a monad. Hope this helps, Martijn. ___ 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] ANN: scion 0.1
On Thu, Aug 27, 2009 at 11:44 AM, Thomas Schillingnomin...@googlemail.com wrote: On 27 Aug 2009, at 09:17, Johan Tibell wrote: Also, I tried to play with the scion-open-cabal-project function. I'm not sure I understand how it's intended to be used. Does it make sure that if you compile a file using C-c C-x C-l the right source directories are used? Could you give a usage example? I eventually want to get rid of it and let scion-load figure out itself when the project needs to be reconfigured. At the moment you have to delete the .dist-scion directory if you changed your .cabal file. :/ My question was probably a bit unclear so let me try to clarify it. What's the purpose of scion-open-cabal-project? Does it set the include path used for subsequent scion-loads? What's the .dist-scion directory and how does it differ from the normal dist directory? One problem I frequently have with emacs-mode is that you can't use it to load a file if * your sources don't live in the same directory as the Cabal file, or Actually, the latest version of haskell-mode has some heuristics. It sets the working directory to where the .cabal file lives. Right. I meant if I don't root my source files in the same directory as the Cabal file it won't work. Cheers, Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Problem with monadic formlets
I'm trying to validate user input against a database (using HaskellDB, but that doesn't seem to be the problem, as replacing the database monadic code with return True gives the same problem. This is part of my code: register :: Database - XForm Registration --register db = Registration $ pure_user * passConfirmed register db = Registration $ (user db) * passConfirmed user :: Database - XForm String user db = pure_user `F.checkM` F.ensureM valid error where valid name = do let q = do t - table user_table restrict (t!user_name .==. constant name) return t rs - query db q return $ null rs error = Username already exists in the database! pure_user :: XForm String pure_user = input `F.check` F.ensure valid error where input = Username `label` F.input Nothing valid = (= 3) . length error = Username must be three characters or longer. passConfirmed :: XForm String passConfirmed = fst $ passwords `F.check` F.ensure equal error where passwords = (,) $ pass Password * pass Password (confirm) equal (a, b) = a == b error = The entered passwords do not match! pass :: String - XForm String pass caption = input `F.check` F.ensure valid error where input = caption `label` F.password Nothing valid = (=6) . length error = Password must be six characters or longer. If I uncomment the commented line, and comment out the line after it (in register), then everything works as expected. However, using it as it is, one of the calls to pass gets the user's name for validation (and consequently either fails if the user name is only 5 characters, or the comparison of the two passwords fail (unless I type the user name as the password). I thought the applicative style meant the effects did not influence one another, but here there is clear contamination. What am i doing wrong? -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping over multiple values of a list at once?
Hi Max How about a paramorphism? slideAvg3 :: [Int] - [Int] slideAvg3 = para phi [] where phi x ((y:z:_),acc) = average3 x y z : acc phi x (_,acc) = acc -- helpers -- paramorphism (generalizes catamorphism (fold)) para :: (a - ([a], b) - b) - b - [a] - b para phi b [] = b para phi b (x:xs) = phi x (xs, para phi b xs) average3 :: Int - Int - Int - Int average3 a b c = round $ (fromIntegral $ a+b+c)/3 I haven't tested for efficiency though. Best wishes Stephen 2009/8/27 Max Rabkin max.rab...@gmail.com: However, we don't really need the sliding windows themselves, just the sliding sum. There might be a slightly more efficient way to do that, but I'll leave it as an exercise for you or somebody else. --Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Inexplicable allocation
Hello, this is my first posting to this List, I hope everything goes well. Seeing that the haskell is currently poorly represented in the fasta benchmark at http://shootout.alioth.debian.org/u64q/benchmark.php?test=fastalang=all , I decided to help out the contributors a bit. My draft already performs considerably better than the current program, but while optimizing I ran into a weird problem. I already reported this as a ghc bug, but on IRC I was encouraged to also describe my problem here. Source of the program: http://rohanlean.de/pub/ghc_alloc/fasta.hs Core: http://rohanlean.de/pub/ghc_alloc/fasta.core Relevant port of the core (`gen' with inlined `pick'): http://rohanlean.de/pub/ghc_alloc/fasta_snip.core Running with the -p option suggested that `gen' and `pick' allocate a lot of memory throughout the run of the program (that memory is not retained). I managed to confirm that for non-profiling builds by observing how the the output of -sstderr changed when I modified `gen' to call itself fewer times. This came as a surprise, because expected these two functions to be completely allocation free, and the core does not suggest any allocation to me. I would very much welcome explanations for these reported allocations. Thank you, Rohan Lean ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation
Hallo everyone, as Haskell uses the Lazy Evaluation reduction policy also known as Outermost Graph Reduction, I was wondering if the following simple implementation of the Fibonacci sequence would result in linear runtime behaviour. fib :: Integer - Integer fib 0 = 0 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1) Is the following reduction sequence realistic, or am I admitting to much intelligence to the Haskell Compiler? http://www.bilder-hochladen.net/files/bxlk-6-jpg.html http://www.bilder-hochladen.net/files/thumbs/bxlk-6.jpg I hope someone can help... -- View this message in context: http://www.nabble.com/Reduction-Sequence-of-simple-Fibonacci-sequence-implementation-tp25178377p25178377.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation
Hello SimonK77, Thursday, August 27, 2009, 11:24:14 PM, you wrote: for linear timing it needs memoization of previous results. haskell compilers doesn't do it automatically since it may change space properties of program. well-known example is: main = print (sum[1..1000] + prod[1..1000]) in order to use memoization you should declare fib as array: fib = array (1,999) ([1,1]++map (\i - fib!(i-1) + fib!(i-2)) [3..999]) Hallo everyone, as Haskell uses the Lazy Evaluation reduction policy also known as Outermost Graph Reduction, I was wondering if the following simple implementation of the Fibonacci sequence would result in linear runtime behaviour. fib :: Integer - Integer fib 0 = 0 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1) Is the following reduction sequence realistic, or am I admitting to much intelligence to the Haskell Compiler? I hope someone can help... View this message in context: Reduction Sequence of simple Fibonacci sequence implementation Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Reduction Sequence of simple Fibonacci sequence implementation
SimonK77 simonkaltenbacher at googlemail.com writes: as Haskell uses the Lazy Evaluation reduction policy also known as Outermost Graph Reduction, I was wondering if the following simple implementation of the Fibonacci sequence would result in linear runtime behaviour. fib :: Integer - Integer fib 0 = 0 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1) Is the following reduction sequence realistic, or am I admitting to much intelligence to the Haskell Compiler? You are, as easily seen when you try to calculate (fib 30). A version that works: import Data.MemoTrie fib :: Integer - Integer fib = memo \n - case n of 0 - 0 1 - 1 n - fib (n-1) + fib (n-2) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation
On Thu, Aug 27, 2009 at 12:32 PM, Bulat Ziganshinbulat.zigans...@gmail.com wrote: Hello SimonK77, Thursday, August 27, 2009, 11:24:14 PM, you wrote: for linear timing it needs memoization of previous results. haskell compilers doesn't do it automatically since it may change space properties of program. well-known example is: main = print (sum[1..1000] + prod[1..1000]) in order to use memoization you should declare fib as array: fib = array (1,999) ([1,1]++map (\i - fib!(i-1) + fib!(i-2)) [3..999]) Unless I'm mistaken this one is also memoized and simpler: fibs = 1 : 1 : zipWith (+) fibs (tail fibs) Then to get a specific fib, zero index, you do: fib n = fibs !! n Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation
Hello SimonK77, Thursday, August 27, 2009, 11:24:14 PM, you wrote: list-based memoization for fibs should look as fibs = 1 : 1 : map (sum.take 2) (tails fibs) Hallo everyone, as Haskell uses the Lazy Evaluation reduction policy also known as Outermost Graph Reduction, I was wondering if the following simple implementation of the Fibonacci sequence would result in linear runtime behaviour. fib :: Integer - Integer fib 0 = 0 fib 1 = 1 fib n = fib (n - 2) + fib (n - 1) Is the following reduction sequence realistic, or am I admitting to much intelligence to the Haskell Compiler? I hope someone can help... View this message in context: Reduction Sequence of simple Fibonacci sequence implementation Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[Haskell-cafe] duction Sequence of simple Fibonacci sequence implementation
Am Donnerstag 27 August 2009 21:41:49 schrieb Jason Dagit: On Thu, Aug 27, 2009 at 12:32 PM, Bulat Ziganshinbulat.zigans...@gmail.com wrote: Hello SimonK77, Thursday, August 27, 2009, 11:24:14 PM, you wrote: for linear timing it needs memoization of previous results. haskell compilers doesn't do it automatically since it may change space properties of program. well-known example is: main = print (sum[1..1000] + prod[1..1000]) in order to use memoization you should declare fib as array: fib = array (1,999) ([1,1]++map (\i - fib!(i-1) + fib!(i-2)) [3..999]) Unless I'm mistaken this one is also memoized and simpler: fibs = 1 : 1 : zipWith (+) fibs (tail fibs) Should be fibs = 0:1:zipWith (+) fibs (tail fibs) of course. Then to get a specific fib, zero index, you do: fib n = fibs !! n Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problem with monadic formlets
Hello, I hacked your code into a runnable example, and it seems to work for me. What happens if you do something like: let (c, xml, _) = runFormState [(input0,Left name), (input1, Left password), (input2, Left password) ] (register foo) in c = \r - do print xml print r (except you need to pass in a Database instead of foo as the argument to register.) I get: label Username/label input type=text name=input0 id=input0 value=name /label Password/label input type=password name=input1 id=input1 value=password /label Password (confirm)/label input type=password name=input2 id=input2 value=password / Success (Registration name password) Which looks correct to me. Your code looks fine to me as well... Perhaps the error is not in the code you pasted, but somewhere else. I am running on an older, and somewhat forked version of Formlets, so there could also be a bug in the new code I guess. Though, that seems unlikely. But it is worth noting that we are not using the same version of the formlets library. - jeremy At Thu, 27 Aug 2009 16:09:18 +0100, Colin Paul Adams wrote: I'm trying to validate user input against a database (using HaskellDB, but that doesn't seem to be the problem, as replacing the database monadic code with return True gives the same problem. This is part of my code: register :: Database - XForm Registration --register db = Registration $ pure_user * passConfirmed register db = Registration $ (user db) * passConfirmed user :: Database - XForm String user db = pure_user `F.checkM` F.ensureM valid error where valid name = do let q = do t - table user_table restrict (t!user_name .==. constant name) return t rs - query db q return $ null rs error = Username already exists in the database! pure_user :: XForm String pure_user = input `F.check` F.ensure valid error where input = Username `label` F.input Nothing valid = (= 3) . length error = Username must be three characters or longer. passConfirmed :: XForm String passConfirmed = fst $ passwords `F.check` F.ensure equal error where passwords = (,) $ pass Password * pass Password (confirm) equal (a, b) = a == b error = The entered passwords do not match! pass :: String - XForm String pass caption = input `F.check` F.ensure valid error where input = caption `label` F.password Nothing valid = (=6) . length error = Password must be six characters or longer. If I uncomment the commented line, and comment out the line after it (in register), then everything works as expected. However, using it as it is, one of the calls to pass gets the user's name for validation (and consequently either fails if the user name is only 5 characters, or the comparison of the two passwords fail (unless I type the user name as the password). I thought the applicative style meant the effects did not influence one another, but here there is clear contamination. What am i doing wrong? -- Colin Adams Preston Lancashire ___ 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] Killing a thread blocking on a foreign call
Hi List, I'm trying to kill a thread (during program cleanup) that is almost always going to be perma-blocking on a foreign call (read). It seems that there's no facility to do this built into Haskell at this point, or is there? /jve ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell] Re: [Haskell-cafe] ANNOUNCE: jhc 0.7.1
There should be no excuses for not giving jhc a whirl. Agreed. In a lot of ways, jhc seems like a Haskell compiler done right. It generates very fast and lean binaries - using C as an intermediary language - which makes it a natural cross-compiler and indicates it should not be too difficult to write a back-end for the CIL and the jvm. On the other hand, it is still far away from GHC features-wise. So there is definitively room for people looking to contribute to a compiler with a high potential. Wouldn't that be fun? Sylvain. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Applicative and Monad transformers
On 27 Aug 2009 at 07:48, Ralf Hinze wrote: \ x - (v = \ a - return ((u x) a)) x = { definition of = } \ x - (\ a - return ((u x) a)) (v x) x Something seems to have gone wrong here - shouldn't that be \x - (\y - (\a - return ((u x) a)) (v y) y) x = { beta } \x - (\a - return ((u x) a)) (v x) x ? ... but then we appear to end up in the same place. Now all I've got to do is figure out what you were trying to establish in the first place. :-) I don't entirely follow what the OP's up to, so you may have a point, but it's far from clear. You're talking about the reader monad, whereas he's talking about the effects in the ReaderT-transformed monad. -- Iain Alexander i...@stryx.demon.co.uk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Is logBase right?
Prelude toRational 697.04157958259998 3065621287177675 % 4398046511104 Prelude toRational 697.0415795826 3065621287177675 % 4398046511104 As you can see, both numbers are represented by the same Double. Haskell prints a Double with the simplest number that converts back to the same bit pattern. So there's no keep more decimals, just a matter of string conversion. -- Lennart On Tue, Aug 25, 2009 at 7:11 PM, Ketil Maldeke...@malde.org wrote: Steve stevech1...@yahoo.com.au writes: Also, I had a problem using floating point in Python where round(697.04157958254996, 10) gave 697.04157958259998 Its been fixed in the latest versions of Python: round(697.04157958254996, 10) 697.0415795825 ghci roundN 697.04157958254996 10 697.0415795826 Is there something special with this number? Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. 697.04157958259998 697.04157958259998 12345.678901234567890 12345.678901234567 GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude 697.04157958259998 697.0415795826 Prelude 12345.678901234567890 12345.678901234567 So, Python manages to keep more decimals than GHC for your number, but for other numbers, the precision appears to be the same. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Applicative and Monad transformers
At Fri, 28 Aug 2009 01:01:09 +0100, I don't entirely follow what the OP's up to, so you may have a point, but it's far from clear. You're talking about the reader monad, whereas he's talking about the effects in the ReaderT-transformed monad. oops. Apparently I forgot to explictly state the issue :) I am using ReaderT to lookup symbols in an environment. I am using the inner monad/applicative functor to record whether the lookup failed or succeeded. So I essential have the type: ReaderT [(a,b)] (Either [a]) b [(a,b)] is the environment. In the end I get back a value: Either [a] b where [a] is all the symbols that weren't found or 'b' is the final value. For example, if I have: looker :: ReaderT [(String, Int)] (Either [String]) (Int, Int, Int) looker = ((,,) $ look foo * look bar * look baz) and none of the symbols are in the enviroment then I should get: Left [foo, bar, baz] The issue is that if I use the free (?) applicative functor instance for ReaderT then I only get back the *first* failure: Left [foo] But, if I used my alternative definition, then I get back all the failures. My concern is that my alternative version was somehow violating an applicative functor law. My secondary concern was the free version was somehow violating a law. It seems though, that both are valid... - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Applicative and Monad transformers
At Thu, 27 Aug 2009 10:47:43 -0400, Job Vranish wrote: I've often wanted an applicative instance for a datatype that didn't match the monad instance. It would be nice if there was a way to hide instances so that they could be redefined. Yeah, this is similar to the issue of multiple sensible instances for Data.Monoid. This issue has come up several times for me recently. A bit of a shortcoming in the type class design I think. There was once a proposal to help address this, but it never gained tracation: http://scholar.google.com/scholar?hl=enlr=cluster=8306039955712318110um=1ie=UTF-8ei=JTmXSvmTJ4a4M6TJlfkNsa=Xoi=science_linksresnum=1ct=sl-allversions Recently I have wondered if module functors might somehow be a solution somehow. But I have not actually investigated at all. - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: moe html combinator
hand written html is fine, except for the closing tags: what if html' - do head' - do meta [http_equiv Content-Type, content text/html; charset-utf-8] (/) title' - str my title link [rel icon, _type image/png, href panda_icon.png] (/) body' - do div [_class container] - do str hello world produces html head meta http-equiv=Content-Type content=text/html; charset-utf-8 /meta title my title /title link rel=icon type=image/png href=panda_icon.png /link /head body div class=container hello world /div /body /html That's moe. There's also extra dsl sugar / flavors for your convienence, including (currently available) markdown and kawaii. It's a new library, tries to bring some haskell fun back to web programming, so .. enjoy. - moe: http://hackage.haskell.org/package/moe -- jinjing ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: moe html combinator
Hello Jinjing, Friday, August 28, 2009, 9:08:58 AM, you wrote: hand written html is fine, except for the closing tags: may be it's possible to omit them using type machinery? link [rel icon, _type image/png, href panda_icon.png] (/) it contains unpredictable mix of xxx', _xxx and xxx identifiers. how about using the same style, say _xxx, for everything? and stop reusing Prelude operators, in particular, replace - with $? -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe