Re: [Haskell-cafe] Re: Codec.Crypto.RSA question

2010-11-20 Thread Charles-Pierre Astolfi
at crans.org writes: Hi -cafe, I have a question about Codec.Crypto.RSA: how to enforce that (informally) decrypt . encrypt = id Consider this code: That's certainly what I would expect and one of the unit tests  that comes with http://hackage.haskell.org/packages/archive/Crypto/4.2.2/doc/html

Re: [Haskell-cafe] Re: Codec.Crypto.RSA question

2010-11-20 Thread Dominic Steintiz
Charles-Pierre Astolfi wrote: Here's a working example: import qualified Codec.Crypto.RSA as Crypto import System.Random (mkStdGen) import Data.Binary (encode) import Data.ByteString.Lazy.UTF8 (toString) n = 1024 (pubKey,privKey,_) = Crypto.generateKeyPair (mkStdGen n) n encrypt ::

Re: [Haskell-cafe] Re: Codec.Crypto.RSA question

2010-11-20 Thread Mathias Weber
) so I guess I have to stick with Codec.Crypto.RSA. Any ideas? -- Cp On Sat, Nov 20, 2010 at 12:50, Dominic Steinitz domi...@steinitz.org wrote: Charles-Pierre Astolfi cpa at crans.org writes: Hi -cafe, I have a question about Codec.Crypto.RSA: how to enforce

[Haskell-cafe] Re: a simple question about types

2010-11-19 Thread JerzM
Thank you for these excellent explanations. Best regards, Jerz -- View this message in context: http://haskell.1045720.n5.nabble.com/a-simple-question-about-types-tp3269519p3272344.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com

[Haskell-cafe] Codec.Crypto.RSA question

2010-11-19 Thread Charles-Pierre Astolfi
Hi -cafe, I have a question about Codec.Crypto.RSA: how to enforce that (informally) decrypt . encrypt = id Consider this code: encrypt2 :: String - ByteString encrypt2 = fst . encrypt (mkStdGen n) pubKey encode decrypt2 :: ByteString - String decrypt2 = toString . decrypt privKey Since

[Haskell-cafe] Quasi quotation question

2010-11-19 Thread jean-christophe mincke
Hello, Is it possible for a quasi quoter to have access to information about haskell identifiers declared before the quasi-quotation? I tried the 'reify' function but without success. Just as in the following exemple: a = 6 x = [$expr|a|] Where the generated haskell code is a= 6 x = a

Re: [Haskell-cafe] Quasi quotation question

2010-11-19 Thread Sterling Clover
On Nov 19, 2010, at 6:00 PM, jean-christophe mincke wrote: Hello, Is it possible for a quasi quoter to have access to information about haskell identifiers declared before the quasi-quotation? Nope. There are staging restrictions in place, since you can't sanely use things that haven't

[Haskell-cafe] Re: a simple question about types

2010-11-18 Thread Jon Fairbairn
:: Integer - Integer One more combination, now I write h x = (2*) x and check once more :t h to get h :: (Num a) = a - a So my question is: why (in this second example) Integer is inferred? What makes a difference? The monomorphism restriction. And default. If you load this into ghci

[Haskell-cafe] a simple question about types

2010-11-17 Thread Jerzy M
a) = a - a So my question is: why (in this second example) Integer is inferred? What makes a difference? Jerz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] a simple question about types

2010-11-17 Thread Alexander Solla
On Nov 17, 2010, at 10:09 AM, Jerzy M wrote: So my question is: why (in this second example) Integer is inferred? What makes a difference? I think there are two things going on. First, the monomorphism restriction is causing the types to be different. I'm not sure why Integer

Re: [Haskell-cafe] a simple question about types

2010-11-17 Thread Daniel Fischer
write h x = (2*) x and check once more :t h to get h :: (Num a) = a - a So my question is: why (in this second example) Integer is inferred? What makes a difference? The monomorphism restriction. As specified in section 4.5.5 of the language report (http://www.haskell.org/onlinereport

Re: [Haskell-cafe] a simple question about types

2010-11-17 Thread Ryan Ingram
Now of course, the followup question is what the heck is a monomorphism restriction and why would I want it? Here is a simple example: expensiveComputation :: Num a = a - a expensiveComputation x = ... something that takes a long time to compute ... ghci :t (expensiveComputation 2

Re: [Haskell-cafe] a simple question about types

2010-11-17 Thread Daniel Fischer
On Wednesday 17 November 2010 20:19:17, Ryan Ingram wrote: Now of course, the followup question is what the heck is a monomorphism restriction and why would I want it? Here is a simple example: snip But if you give g the more general type signature, the expensiveComputation has to get run

[Haskell-cafe] dph question

2010-10-15 Thread Warren Harris
I trying to learn a bit about data parallel haskell, and started from the wiki page here: http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell. Two questions: The examples express the dot product as: dotp_double xs ys = sumP [:x *

[Haskell-cafe] Re: dph question

2010-10-15 Thread steffen
I trying to learn a bit about data parallel haskell, and started from the wiki page here:http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell. Two questions: The examples express the dot product as: dotp_double xs ys = sumP [:x *

Re: [Haskell-cafe] dph question

2010-10-15 Thread Daniel Fischer
On Friday 15 October 2010 14:59:18, Warren Harris wrote: I trying to learn a bit about data parallel haskell, and started from the wiki page here: http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell. Two questions: The examples express the dot product as: dotp_double xs ys = sumP

Re: [Haskell-cafe] dph question

2010-10-15 Thread Warren Harris
Got it - thanks. Any idea about the run-away process problem? Thanks, Warren On Fri, Oct 15, 2010 at 9:32 AM, Daniel Fischer daniel.is.fisc...@web.dewrote: On Friday 15 October 2010 14:59:18, Warren Harris wrote: I trying to learn a bit about data parallel haskell, and started from the

Re: [Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-13 Thread Henning Thielemann
Ben Franksen schrieb: Neil Mitchell wrote: This makes me curious. What's the use case where you want to allow the user to pass arguments on the command line, but you don't want that user to be able to use '--help' to find out what arguments may be passed? I wanted to create a clone of an

Re: [Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-13 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 10/13/10 06:07 , Henning Thielemann wrote: Ben Franksen schrieb: I wanted to create a clone of an existing program that had no help option and instead gave the help output if it saw an invalid option. I find it very annoying if a program

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-12 Thread Neil Mitchell
This makes me curious.  What's the use case where you want to allow the user to pass arguments on the command line, but you don't want that user to be able to use '--help' to find out what arguments may be passed? When you don't want to bother defining the help options/descriptions? :p

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-12 Thread Joachim Breitner
Hi, Am Dienstag, den 12.10.2010, 16:42 +1100 schrieb Ivan Lazar Miljenovic: On 12 October 2010 16:32, Magnus Therning mag...@therning.org wrote: This makes me curious. What's the use case where you want to allow the user to pass arguments on the command line, but you don't want that user

[Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-12 Thread Ben Franksen
Neil Mitchell wrote: This makes me curious.  What's the use case where you want to allow the user to pass arguments on the command line, but you don't want that user to be able to use '--help' to find out what arguments may be passed? I wanted to create a clone of an existing program that had

[Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-12 Thread Ben Franksen
Joachim Breitner wrote: Am Dienstag, den 12.10.2010, 16:42 +1100 schrieb Ivan Lazar Miljenovic: On 12 October 2010 16:32, Magnus Therning mag...@therning.org wrote: This makes me curious. What's the use case where you want to allow the user to pass arguments on the command line, but you

Re: [Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-12 Thread Neil Mitchell
The point here was not so much removing --help, but rather that I want to have control over the 'standard' options (help,version,verbosity) in the same way as for the rest. My program might not have a version, so why offer --version? Or maybe I want a different name for it because the -V is

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-11 Thread Neil Mitchell
Hi Ben, How can I disable the standard arguments 'help' and 'version'? In general I suggest you email the author of the cmdargs package directly, as well as cc'ing the mailing list (otherwise the author might miss this message, as I did!) In CmdArgs there is currently no way to suppress either

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-11 Thread Magnus Therning
On 11/10/10 22:04, Neil Mitchell wrote: Hi Ben, How can I disable the standard arguments 'help' and 'version'? In general I suggest you email the author of the cmdargs package directly, as well as cc'ing the mailing list (otherwise the author might miss this message, as I did!) In CmdArgs

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-11 Thread Ivan Lazar Miljenovic
On 12 October 2010 16:32, Magnus Therning mag...@therning.org wrote: This makes me curious.  What's the use case where you want to allow the user to pass arguments on the command line, but you don't want that user to be able to use '--help' to find out what arguments may be passed? When you

Re: [Haskell-cafe] A model theory question

2010-10-07 Thread Alexander Solla
On Sep 30, 2010, at 1:39 AM, Patrick Browne wrote: I think my original question can be rephrased as: Can type classes preserve satisfaction under the the expansion sentences (signature/theory morphisms inducing a model morphism). According to [1] expansion requires further measures

Re: [Haskell-cafe] A question regarding cmdargs package

2010-10-04 Thread Arie Peterson
On Sun, 03 Oct 2010 19:18:08 +0200, Ben Franksen ben.frank...@online.de wrote: How can I disable the standard arguments 'help' and 'version'? If you're not fully committed to the cmdargs package, you might try my package 'console-program' instead

[Haskell-cafe] Re: A question regarding cmdargs package

2010-10-04 Thread Ben Franksen
Arie Peterson wrote: On Sun, 03 Oct 2010 19:18:08 +0200, Ben Franksen ben.frank...@online.de wrote: How can I disable the standard arguments 'help' and 'version'? If you're not fully committed to the cmdargs package, you might try my package 'console-program' instead

Re: [Haskell-cafe] A parsec question

2010-10-03 Thread Stephen Tetley
Does this one give the expected error message for Parsec3.1 - unfortunately I can't test as I'm still using Parsec 2.1.0.1. parser = block (many digit ? digit) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Re: A parsec question

2010-10-03 Thread Ben Franksen
Stephen Tetley wrote: Does this one give the expected error message for Parsec3.1 - unfortunately I can't test as I'm still using Parsec 2.1.0.1. parser = block (many digit ? digit) Unfortunately, no. Cheers Ben ___ Haskell-Cafe mailing list

[Haskell-cafe] A question regarding cmdargs package

2010-10-03 Thread Ben Franksen
How can I disable the standard arguments 'help' and 'version'? Cheers ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Re: A parsec question

2010-10-03 Thread Antoine Latter
On Sun, Oct 3, 2010 at 11:55 AM, Ben Franksen ben.frank...@online.de wrote: Stephen Tetley wrote: Does this one give the expected error message for Parsec3.1 - unfortunately I can't test as I'm still using Parsec 2.1.0.1. parser = block (many digit ? digit) Unfortunately, no. Cheers Ben

[Haskell-cafe] Re: Re: A parsec question

2010-10-03 Thread Ben Franksen
Antoine Latter wrote: On Sun, Oct 3, 2010 at 11:55 AM, Ben Franksen ben.frank...@online.de wrote: Stephen Tetley wrote: Does this one give the expected error message for Parsec3.1 - unfortunately I can't test as I'm still using Parsec 2.1.0.1. parser = block (many digit ? digit)

Re: [Haskell-cafe] Re: A parsec question

2010-10-02 Thread Antoine Latter
On Wed, Sep 29, 2010 at 1:01 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: On Wednesday 29 September 2010 19:10:22, Ben Franksen wrote: Note the last line mentions only '}'. I would rather like to see   expecting } or digit since the parser could very well accept another digit

[Haskell-cafe] Re: A parsec question

2010-09-30 Thread Christian Maeder
for this behaviour? (2) Is there another combinator that behaves as I would like? (3) Otherwise, how do I write one myself? ask derek.a.elk...@gmail.com (CCed) Cheers Christian I just saw that Christian Maeder answered a similar question recently. I tried his suggestion of using manyTill

[Haskell-cafe] Re: A parsec question

2010-09-30 Thread Ben Franksen
Christian Maeder wrote: Am 29.09.2010 20:01, schrieb Daniel Fischer: On Wednesday 29 September 2010 19:10:22, Ben Franksen wrote: Note the last line mentions only '}'. I would rather like to see expecting } or digit since the parser could very well accept another digit here. parsec2

[Haskell-cafe] Re: Parsec question (new user): unexpected end of input

2010-09-29 Thread Christian Maeder
Am 29.09.2010 05:35, schrieb Peter Schmitz: [...] Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1): unexpected end of input expecting The input was: [...] -- Parsers: taggedContent = do optionalWhiteSpace aTag many tagOrContent aTag many tagOrContent

[Haskell-cafe] Re: Parsec question (new user): unexpected end of input

2010-09-29 Thread Christian Maeder
Am 29.09.2010 09:54, schrieb Christian Maeder: Am 29.09.2010 05:35, schrieb Peter Schmitz: [...] Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1): unexpected end of input expecting The input was: [...] -- Parsers: taggedContent = do optionalWhiteSpace aTag

[Haskell-cafe] Re: Parsec question (new user): unexpected end of input

2010-09-29 Thread Christian Maeder
Am 29.09.2010 11:55, schrieb Christian Maeder: Am 29.09.2010 09:54, schrieb Christian Maeder: Am 29.09.2010 05:35, schrieb Peter Schmitz: [...] Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1): unexpected end of input expecting The input was: [...] -- Parsers:

[Haskell-cafe] A parsec question

2010-09-29 Thread Ben Franksen
I have a question about Parsec. The following program import Control.Applicative ((*),(*)) import Text.Parsec import Text.Parsec.Char block p = char '{' * p * char '}' parser = block (many digit) main = parseTest parser {123a} gives the output parse error at (line 1, column 5

[Haskell-cafe] Re: A parsec question

2010-09-29 Thread Ben Franksen
? I just saw that Christian Maeder answered a similar question recently. I tried his suggestion of using manyTill and bingo: {-# LANGUAGE NoMonomorphismRestriction #-} import Control.Applicative ((*),(*)) import Text.Parsec block p = char '{' * p * char '}' parser = block (manyTill digit (char

Re: [Haskell-cafe] Re: A parsec question

2010-09-29 Thread Daniel Fischer
or accidental. (1) What is the reason for this behaviour? (2) Is there another combinator that behaves as I would like? (3) Otherwise, how do I write one myself? I just saw that Christian Maeder answered a similar question recently. I tried his suggestion of using manyTill and bingo

[Haskell-cafe] Re: Re: A parsec question

2010-09-29 Thread Ben Franksen
write one myself? I just saw that Christian Maeder answered a similar question recently. I tried his suggestion of using manyTill and bingo: {-# LANGUAGE NoMonomorphismRestriction #-} import Control.Applicative ((*),(*)) import Text.Parsec block p = char '{' * p * char '}' parser = block

[Haskell-cafe] Re: Parsec question (new user): unexpected end of input

2010-09-29 Thread Peter Schmitz
Antoine and Christian: Many thanks for your help on this thread. (I am still digesting it; much appreciated; will post when I get it working.) -- Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Question on monad transformers stack

2010-09-28 Thread Arnaud Bailly
Hello Cafe, I have the following type which represents some action using Git newtype (Monad m) = Git m a = Git { runGit :: ErrorT String (StateT Environment m) a } deriving (Monad, MonadState Environment, MonadError String) and the following typeclass whose purpose is to

Re: [Haskell-cafe] A model theory question

2010-09-28 Thread Patrick Browne
Alexander Solla wrote: Doing similar constructions with type classes is possible. I think you might have to use witness types (or even a nice functorial wrapper around your target value in the original algebra, or both) to do generalizations of type classes. For example: class Uneditable

Re: [Haskell-cafe] Question on monad transformers stack

2010-09-28 Thread Jonathan Geddes
Arnaud, You might also consider writing monad-agnostic code: code that doesn't know which monad it is executing in. For example: class (Monad g) = MonadGit g where gitOp1 :: gitOp2 :: instance MonadGit Git where gitOp1 = ... gitOp2 = ... ... intance MonadGit

Re: [Haskell-cafe] Question on monad transformers stack

2010-09-28 Thread Arnaud Bailly
Look rather obvious when explained :-) And this is a pattern I have already used for other code :-( Thanks a lot Jonathan, that's indeed quite helpful. Regards Arnaud On Tue, Sep 28, 2010 at 3:03 PM, Jonathan Geddes geddes.jonat...@gmail.com wrote: Arnaud, You might also consider writing

[Haskell-cafe] Parsec question (new user): unexpected end of input

2010-09-28 Thread Peter Schmitz
I am a new Parsec user, and having some trouble with a relatively simple parser. The grammar I want to parse contains tags (not html) marked by angle brackets (e.g., some tag), with arbitrary text (no angle brackets allowed) optionally in between tags. Tags may not nest, but the input must begin

Re: [Haskell-cafe] A model theory question

2010-09-28 Thread Alexander Solla
On 09/28/2010 03:03 AM, Patrick Browne wrote: I had a look at the types of a and a’. *Main :t a a :: forall a obj. (Uneditable obj) = a - obj *Main :t a' a' :: forall witness a obj. (Refactored obj witness) = Maybe (a - obj) Could you explain the example a little more. This is going to

Re: [Haskell-cafe] Parsec question (new user): unexpected end of input

2010-09-28 Thread Antoine Latter
On Tue, Sep 28, 2010 at 10:35 PM, Peter Schmitz ps.hask...@gmail.com wrote: I am a new Parsec user, and having some trouble with a relatively simple parser. The grammar I want to parse contains tags (not html) marked by angle brackets (e.g., some tag), with arbitrary text (no angle brackets

Re: [Haskell-cafe] A model theory question

2010-09-27 Thread Patrick Browne
Alexander Solla wrote: On 09/26/2010 01:32 PM, Patrick Browne wrote: Bigger how? Under logical implication and its computational analogue? That is to say, do you want the model to be more SPECIFIC, describing a smaller class of objects more richly (i.e, with more logical implications to

Re: [Haskell-cafe] A model theory question

2010-09-27 Thread Alexander Solla
hold at the programming level. Well, my question was more along the lines of do you want bigger (more specific) theories (and so more specific models to interpret them)? or do you want to generalize from a given theory? To do the latter with Haskell, you might create a module that allows

Re: [Haskell-cafe] parsec manyTill documentation question

2010-09-27 Thread Peter Schmitz
On Fri, Sep 24, 2010 at 9:28 PM, Evan Laforge qdun...@gmail.com wrote: simpleComment = do{ string !--                   ; manyTill anyChar (try (string --))                   } Note the overlapping parsers anyChar and string !--, and therefore the use of the try combinator. First, I would

Re: [Haskell-cafe] parsec manyTill documentation question

2010-09-27 Thread Peter Schmitz
Stephen, Thanks much for the pointer to the examples in the sources; found them. (Its nice to learn from the coding style used by the authors.) -- Peter On Sat, Sep 25, 2010 at 12:34 AM, Stephen Tetley stephen.tet...@gmail.com wrote: On 25 September 2010 05:30, Evan Laforge qdun...@gmail.com

[Haskell-cafe] A model theory question

2010-09-26 Thread Patrick Browne
Hi, Below is an assumption (which could be wrong) and two questions. ASSUMPTION 1 Only smaller models can be specified using the sub-class mechanism. For example if we directly make a subclass A = B then every instance of B must also be an instance of A (B implies A or B is a subset of A). Hence,

Re: [Haskell-cafe] A model theory question

2010-09-26 Thread Alexander Solla
On 09/26/2010 01:32 PM, Patrick Browne wrote: Hi, Below is an assumption (which could be wrong) and two questions. ASSUMPTION 1 Only smaller models can be specified using the sub-class mechanism. For example if we directly make a subclass A = B then every instance of B must also be an

Re: [Haskell-cafe] parsec manyTill documentation question

2010-09-25 Thread Stephen Tetley
On 25 September 2010 05:30, Evan Laforge qdun...@gmail.com wrote: I thought the parsec source included some example parsers for simple languages?  In any case, there is lots of material floating around, [Snip] The best documentation is Daan Leijen's original manual, plus the original source

Re: [Haskell-cafe] Simple question about the function composition operator

2010-09-25 Thread wren ng thornton
On 9/24/10 5:35 AM, Axel Benz wrote: Can anybody explain why this happens and how I can compose f and g? Hint: It works fine if f is defined as an unary function. As already mentioned: (g . f) x y = (\z- g (f z)) x y = g (f x) y In order to get it to work you need to say that you want to

[Haskell-cafe] Simple question about the function composition operator

2010-09-24 Thread Axel Benz
Hello, this is maybe a simple question: cbinary :: a - b - (a - b - b) - (b - c) - c -- Version 1 works: cbinary x y f g = g (f x y) -- Version 2 should be exactly the same according -- to my understanding of the . operator definition, -- but fails with: -- Occurs check

Re: [Haskell-cafe] Simple question about the function composition operator

2010-09-24 Thread Miguel Mitrofanov
(g . f) x y = (\z - g (f z)) x y = g (f x) y, and you need g (f x y), which is definitely not the same thing. 24.09.2010 13:35, Axel Benz пишет: Hello, this is maybe a simple question: cbinary :: a - b - (a - b - b) - (b - c) - c -- Version 1 works: cbinary x y f g = g (f x y

[Haskell-cafe] parsec manyTill documentation question

2010-09-24 Thread Peter Schmitz
I am new to parsec and having difficulty understanding the explanation of manyTill in http://legacy.cs.uu.nl/daan/download/parsec/parsec.html. (I really appreciate having this doc by the way; great reference.) I.e.: manyTill :: GenParser tok st a - GenParser tok st end - GenParser tok st [a]

Re: [Haskell-cafe] parsec manyTill documentation question

2010-09-24 Thread Evan Laforge
[ sorry, forgot reply to all ] simpleComment = do{ string !--                   ; manyTill anyChar (try (string --))                   } Note the overlapping parsers anyChar and string !--, and therefore the use of the try combinator. First, I would have expected it to instead say: Note

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-21 Thread Christopher Tauss
Thanks Richard and the others who responded to my query. I truly appreciate you taking the time and effort to respond to me (and the community) with your thoughts. I had been reading about recursion, and was thinking only of that approach to solve this. My main reson for looking into Haskell is

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread Henning Thielemann
Christopher Tauss schrieb: I am a professional programmer with 11 years experience, yet I just do not seem to be able to get the hang of even simple things in Haskell. I am trying to write a function that takes a list and returns the last n elements. Looking through the glasses of lazy

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread Alberto G. Corona
2010/9/18 Daniel Fischer daniel.is.fisc...@web.de n_lastn n = reverse . take n . reverse Which is the most elegant definition, but it's an O(length list) space operation (as are all others proposed so far). T No!. You forget laziness!. it is 0(n) with n= the parameter passed to

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread Henning Thielemann
Luke Palmer schrieb: I think this is O(n) time, O(1) space (!). lastk :: Int - [a] - [a] lastk k xs = last $ zipWith const (properTails xs) (drop k xs) where properTails = tail . tails If (drop k xs) is empty, this yields an error when calling 'last'. This might be a bug or a feature.

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread Jean-Marie Gaillourdet
Hi Alberto, On 20.09.2010, at 10:53, Alberto G. Corona wrote: 2010/9/18 Daniel Fischer daniel.is.fisc...@web.de n_lastn n = reverse . take n . reverse Which is the most elegant definition, but it's an O(length list) space operation (as are all others proposed so far). T No!. You

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread James Andrew Cook
On Sep 20, 2010, at 5:10 AM, Jean-Marie Gaillourdet wrote: Hi Alberto, On 20.09.2010, at 10:53, Alberto G. Corona wrote: 2010/9/18 Daniel Fischer daniel.is.fisc...@web.de n_lastn n = reverse . take n . reverse Which is the most elegant definition, but it's an O(length list) space

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread Jean-Marie Gaillourdet
Hi James, On 20.09.2010, at 15:20, James Andrew Cook wrote: Lazyness helps helps to reduce work if your input list is lazily constructed and your function forces the returned element. Then you don't have to force all elements of the list, only the last one. Let's say l = [e_0, ..., e_n].

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread Daniel Fischer
On Monday 20 September 2010 15:20:53, James Andrew Cook wrote: On Sep 20, 2010, at 5:10 AM, Jean-Marie Gaillourdet wrote: Hi Alberto, On 20.09.2010, at 10:53, Alberto G. Corona wrote: 2010/9/18 Daniel Fischer daniel.is.fisc...@web.de n_lastn n = reverse . take n . reverse

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread Daniel Peebles
Have we put off the ultra-newbie by derailing his simple question into a discussion on subtle issues he shouldn't care about this early on? On Mon, Sep 20, 2010 at 3:49 PM, Daniel Fischer daniel.is.fisc...@web.dewrote: On Monday 20 September 2010 15:20:53, James Andrew Cook wrote: On Sep 20

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread James Andrew Cook
would ever be needed. On Sep 20, 2010, at 10:22 AM, Daniel Peebles wrote: Have we put off the ultra-newbie by derailing his simple question into a discussion on subtle issues he shouldn't care about this early on? Probably. It's both a joy and a curse having a community so enthusiastic

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-20 Thread Richard O'Keefe
On Sep 18, 2010, at 7:51 PM, Christopher Tauss wrote: Hello Haskell Community - I am a professional programmer with 11 years experience, yet I just do not seem to be able to get the hang of even simple things in Haskell. I am trying to write a function that takes a list and returns the

Re: [Haskell-cafe] Re: Ultra-newbie Question

2010-09-20 Thread Luke Palmer
On Sun, Sep 19, 2010 at 5:01 PM, Henrique Becker henriquebecke...@gmail.com wrote: Why not? import Data.Number.Nat as N lastN :: Integral b = b - [a] - [a] lastN n xs = N.drop (N.length xs - n') xs        where n' = N.toNat n Wow. That is gorgeous! I think it's basically the same idea as

Re: [Haskell-cafe] Re: Ultra-newbie Question

2010-09-20 Thread Luke Palmer
On Mon, Sep 20, 2010 at 5:11 PM, Luke Palmer lrpal...@gmail.com wrote: On Sun, Sep 19, 2010 at 5:01 PM, Henrique Becker henriquebecke...@gmail.com wrote: Why not? import Data.Number.Nat as N lastN :: Integral b = b - [a] - [a] lastN n xs = N.drop (N.length xs - n') xs        where n' =

Re: [Haskell-cafe] Re: Ultra-newbie Question

2010-09-20 Thread Henrique Becker
Thanks, It's my first post. If you not import Prelude is more clear (N. is horrible): import Prelude ((-), Integral) import Data.Number.Nat (drop, length, toNat) lastN :: Integral b = b - [a] - [a] lastN n xs = drop (length xs - n') xs where n' = toNat n P.S.: You benchmarked? I

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-19 Thread Aai
I like this one! Here's a variant using fold: lastk :: Int - [a] - [a] lastk k xs = foldl' (const.tail) xs (drop k xs) or point free: lastk = ap (foldl' (const. tail)). drop Hallo Luke Palmer, je schreef op 18-09-10 22:42: I think this is O(n) time, O(1) space (!). lastk :: Int - [a] - [a]

[Haskell-cafe] Re: Ultra-newbie Question

2010-09-19 Thread Henrique Becker
Why not? import Data.Number.Nat as N lastN :: Integral b = b - [a] - [a] lastN n xs = N.drop (N.length xs - n') xs where n' = N.toNat n Not import Prelude maybe make more clear. []'s Henrique Becker ___ Haskell-Cafe mailing list

[Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Christopher Tauss
Hello Haskell Community - I am a professional programmer with 11 years experience, yet I just do not seem to be able to get the hang of even simple things in Haskell. I am trying to write a function that takes a list and returns the last n elements. There may be a function which I can just call

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Ivan Lazar Miljenovic
On 18 September 2010 17:51, Christopher Tauss ctau...@gmail.com wrote: Hello Haskell Community - I am a professional programmer with 11 years experience, yet I just do not seem to be able to get the hang of even simple things in Haskell.  I am trying to write a function that takes a list and

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread David Terei
Here is a more manual way to do it, hopefully this shows the approach required. You don't need to store anything, just keep removing the head of the list until its of the size you want. n_lastn :: Int - [a] - [a] n_lastn n xs = let len = length xs - n drp = if len 0 then 0 else len

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Nils Schweinsberg
Am 18.09.2010 09:51, schrieb Christopher Tauss: I am trying to write a function that takes a list and returns the last n elements. last_n n = fst . foldr step ([], n) where step _ (xs, 0) = (xs, 0) step x (xs, n) = (x:xs, n-1) ___

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Jake McArthur
On 09/18/2010 02:51 AM, Christopher Tauss wrote: I am trying to write a function that takes a list and returns the last n elements. This may just be for the sake of learning, in which case this is fine, but usually, needing to do this would be a sign that you are using lists improperly

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Christopher Tauss
Thanks you Ivan and David for clarifying this. Best Regards, Chris On Sat, Sep 18, 2010 at 3:55 AM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: On 18 September 2010 17:51, Christopher Tauss ctau...@gmail.com wrote: Hello Haskell Community - I am a professional programmer

[Haskell-cafe] Re: Ultra-newbie Question

2010-09-18 Thread Maciej Piechotka
On Sat, 2010-09-18 at 03:51 -0400, Christopher Tauss wrote: Hello Haskell Community - I am a professional programmer with 11 years experience, yet I just do not seem to be able to get the hang of even simple things in Haskell. I am trying to write a function that takes a list and returns

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Daniel Fischer
On Saturday 18 September 2010 19:44:38, Jake McArthur wrote: On 09/18/2010 02:51 AM, Christopher Tauss wrote: I am trying to write a function that takes a list and returns the last n elements. This may just be for the sake of learning, in which case this is fine, but usually, needing to do

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Luke Palmer
I think this is O(n) time, O(1) space (!). lastk :: Int - [a] - [a] lastk k xs = last $ zipWith const (properTails xs) (drop k xs) where properTails = tail . tails Luke On Sat, Sep 18, 2010 at 1:51 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: On Saturday 18 September 2010 19:44:38,

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Daniel Fischer
On Saturday 18 September 2010 22:42:57, Luke Palmer wrote: I think this is O(n) time, O(1) space (!). lastk :: Int - [a] - [a] lastk k xs = last $ zipWith const (properTails xs) (drop k xs)     where properTails = tail . tails Luke No, it's O(k) too. You zip [[x_n, x_{n+1}, ... ], ... ]

Re: [Haskell-cafe] Ultra-newbie Question

2010-09-18 Thread Alexander Solla
On Sep 18, 2010, at 12:51 AM, Christopher Tauss wrote: I am a professional programmer with 11 years experience, yet I just do not seem to be able to get the hang of even simple things in Haskell. I am trying to write a function that takes a list and returns the last n elements.

Re: [Haskell-cafe] Re: Ultra-newbie Question

2010-09-18 Thread Gregory Crosswhite
Translation: Look at Data.Sequence sometime. On 9/18/10 11:15 AM, Maciej Piechotka wrote: On Sat, 2010-09-18 at 03:51 -0400, Christopher Tauss wrote: Hello Haskell Community - I am a professional programmer with 11 years experience, yet I just do not seem to be able to get the hang of even

Re: [Haskell-cafe] Re: Ultra-newbie Question

2010-09-18 Thread Gregory Crosswhite
Translation: Look at Data.Sequence sometime. On 9/18/10 11:15 AM, Maciej Piechotka wrote: On Sat, 2010-09-18 at 03:51 -0400, Christopher Tauss wrote: Hello Haskell Community - I am a professional programmer with 11 years experience, yet I just do not seem to be able to get the hang of even

[Haskell-cafe] A question about threading state

2010-09-16 Thread michael rice
I've been playing around with State Monads. Two I looked at earlier used *sequence* and *replicate* but when I came to this one I found myself puzzling over how to structure the problem when there was no predetermined count of how many times to thread the state. == Program 1

Re: [Haskell-cafe] Simple Parsec example, question

2010-09-15 Thread Peter Schmitz
Antoine, Thank you very much for your reply. Adding type sigs did help me think about it. I got it to work. I replaced: eol = char '\n' textLines = endBy eol with: textLine :: Parser String textLine = do x - many (noneOf \n) char '\n' return x textLines :: Parser [String]

Re: [Haskell-cafe] Simple Parsec example, question

2010-09-15 Thread Daniel Fischer
On Wednesday 15 September 2010 23:01:34, Peter Schmitz wrote: textLine :: Parser String textLine = do    x - many (noneOf \n)    char '\n'    return x textLines :: Parser [String] textLines = many textLine And it can probably be coded more succinctly that that (suggestions

Re: [Haskell-cafe] Simple Parsec example, question

2010-09-15 Thread Peter Schmitz
Daniel, Thanks much; the more I learn Haskell and Parsec, the more I like them. -- Peter On Wed, Sep 15, 2010 at 4:02 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: On Wednesday 15 September 2010 23:01:34, Peter Schmitz wrote: textLine :: Parser String textLine = do    x - many

[Haskell-cafe] Question on concurrency

2010-09-14 Thread Arnaud Bailly
Hello Haskellers, Having been pretty much impressed by Don Stewart's Practical Haskell (http://donsbot.wordpress.com/2010/08/17/practical-haskell/), I started to write a Haskell script to run maven jobs (yes, I know...). In the course of undertaking this fantastic endeavour, I started to use the

Re: [Haskell-cafe] Question on concurrency

2010-09-14 Thread Neil Brown
On 14/09/10 07:45, Arnaud Bailly wrote: What surprised me is that I would expect the behaviour of the two functions to be different: - in doRunMvnInIO, I would expect stdout's content to be printed before stderr, ie. the 2 threads are ordered because I call takeMVar in between calls to forkIO

<    2   3   4   5   6   7   8   9   10   11   >