Re: [Haskell-cafe] Using _ on the RHS of an equation?

2011-04-05 Thread Paul Keir
Hi Jason, I like the idea. I've seen some code from Oleg Kiselyov which uses __ (two underscores) in this way. The thing that stops me though, is when I get it wrong, and undefined fires somewhere, but I don't know where. Something like you propose, but with a line number, would be sweet. Paul

[Haskell-cafe] Largest types in SYB

2009-12-18 Thread Paul Keir
I was looking for a simple generic technique targeting and transforming the largest terms of a particular type. For example, with Expr and Val declared as: data Expr = Val Val | Add Expr Expr | Sub Expr Expr deriving (Show, Eq, Typeable, Data) data Val = Var String | Struct [Expr] deriving

[Haskell-cafe] [: Where the bracket things are? :]

2009-06-29 Thread Paul Keir
I'd like to add my own custom list delimiters to ghc; such as the [: and :] of Data Parallel Haskell. The purpose is mainly to learn a little about GHC's internals. Any suggestions on the GHC files I should look at first? Alternatively, maybe this is actually possible from outside the

[Haskell-cafe] ghci and applicative

2009-06-12 Thread Paul Keir
Hi, I'm finding that some data types which use Applicative to instantiate the Num class, give responses I wasn't expecting at the ghci prompt. A simple example is list: import Control.Applicative instance (Num a) = Num [a] where as + bs = (+) $ as * bs (*) = undefined;abs = undefined

RE: [Haskell-cafe] ghci and applicative

2009-06-12 Thread Paul Keir
Thanks Ryan, I'm slowly becoming aware of the effects of Monomorphism. I'll look again at Neil Mitchell's blog post. I guess it's the same thing when I try: let a = 1 a + 1.0 I'm taking the mono as a clue that the type inferencing will complete after each ghci carriage return; once only. In

[Haskell-cafe] Nested Lists

2009-06-04 Thread Paul Keir
Hi all, If I have a list, and I'd like to convert it to a list of lists, each of length n, I can use a function like bunch: bunch _ [] = [] bunch n as = let (c,cs) = splitAt n as in c:bunch n cs bunch 8 [1..16] [[1,2,3,4,5,6,7,8],[9,10,11,12,13,14,15,16]] If I now want to do the same for the

[Haskell-cafe] RE: Nested Lists

2009-06-04 Thread Paul Keir
Emil, Felipe, Thanks. I don't know Type Families, but take the point that the input can be parameterised with something something other than a list. i.e. (8 :+: 4 :+: 2 :+: ()) presumably has the same type as (4 :+: 2 :+: ()). My intention was to use common list functions on the sublists, but

[Haskell-cafe] iota

2009-06-01 Thread Paul Keir
Hi all, I was looking for an APL-style iota function for array indices. I noticed range from Data.Ix which, with a zero for the lower bound (here (0,0)), gives the values I need: let (a,b) = (2,3) index ((0,0),(a-1,b-1)) [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)] However, I need the

[Haskell-cafe] RE: iota

2009-06-01 Thread Paul Keir
[xs1,xs2, ... xsn] = [[x1,x2, ... , xn] | x1 - xs1, x2 - xs2, ... , xn - xsn] Using this, you can reduce your iota function to a powerful one-liner: iota = sequence . map (enumFromTo 0 . pred) Kind regards, Raynor Vliegendhart From: Paul Keir Sent: 01 June 2009 10:01

[Haskell-cafe] [] == []

2009-05-29 Thread Paul Keir
Hi all, GHC is not happy with this: f = [] == [] nor this: f' = ([]::(Eq a) = [a]) == ([]::(Eq a) = [a]) but this is OK: f'' = ([]::[Integer]) == ([]::[Integer]) GHCI is comfortable with [] == [], so why not GHC? 'Just curious. Cheers, Paul ___

RE: [Haskell-cafe] [] == []

2009-05-29 Thread Paul Keir
f''' = ([]::[()]) == ([]::[()]) (Very pretty.) So why doesn't ghc have 'default' instances? -Original Message- From: Eugene Kirpichov [mailto:ekirpic...@gmail.com] Sent: Fri 29/05/2009 10:51 To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] [] == [][MESSAGE

[Haskell-cafe] Floating instance and pi

2009-05-29 Thread Paul Keir
Hi, I'd like to make my ADT an instance of the Floating class, but I'm not sure what to put for pi, and GHC gives a warning without it: Warning: No explicit method nor default method for `GHC.Float.pi' I tried setting it to undefined, but that gives an error: `pi' is not a (visible) method of

RE: [Haskell-cafe] Floating instance and pi

2009-05-29 Thread Paul Keir
Oops, I was hiding the Prelude's pi. My apologies. -Original Message- From: Deniz Dogan [mailto:deniz.a.m.do...@gmail.com] Sent: Fri 5/29/2009 5:01 PM To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Floating instance and pi[MESSAGE NOT SCANNED] 2009/5/29 Paul Keir

RE: [Haskell-cafe] Type class context propagation investigation[MESSAGE NOT SCANNED]

2009-05-28 Thread Paul Keir
Thanks. GHC at one stage suggested I add (Num a) = to my Num instance (after I'd added (Eq a) = to my Eq instance) and I didn't make the connection. -Original Message- From: Ryan Ingram [mailto:ryani.s...@gmail.com] Sent: Thu 28/05/2009 01:18 To: Paul Keir Cc: haskell-cafe@haskell.org

RE: [Haskell-cafe] Type class context propagation investigation

2009-05-28 Thread Paul Keir
Thanks Wren, that makes sense. Ryan Ingram wrote: Think of classes like data declarations; an instance with no context is a constant, and one with context is a function. Here's a simple translation of your code into data; this is very similar to the implementation used by GHC for

RE: [Haskell-cafe] The essence of my monad confusion

2009-05-27 Thread Paul Keir
Thanks for all the help. The simplified example indeed threw away too much. There were no side effects. Brent, of course I couldn't create your function; though I gained through trying. I then found it useful to consider the type of: fmap (\x - putStrLn x) getLine which is IO (IO ()) and hence

[Haskell-cafe] Type class context propagation investigation

2009-05-27 Thread Paul Keir
Hi, How does the context of a class instance declaration affect its subclasses? The Num class instance outlined below has its requirement for Eq and Show satisfied on the preceding lines, and the code will compile. But if I, say, add an (Eq a) constraint to the Eq instance, in preparation for

[Haskell-cafe] The essence of my monad confusion

2009-05-02 Thread Paul Keir
On the wiki page for Applicative Functors (http://www.haskell.org/haskellwiki/Applicative_functor) a familiar characteristic of monads is quoted; that they allow you to run actions depending on the outcomes of earlier actions. I feel comfortable with Functors and Applicative Functors, but I

RE: [Haskell-cafe] fromInteger for Lists

2009-05-02 Thread Paul Keir
morris Sent: Sat 02/05/2009 00:13 To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] fromInteger for Lists[MESSAGE NOT SCANNED] 2009/5/1 Paul Keir pk...@dcs.gla.ac.uk: There's nothing better than making a data type an instance of Num. In particular, fromInteger is a joy. But how

[Haskell-cafe] fromInteger for Lists

2009-05-01 Thread Paul Keir
There's nothing better than making a data type an instance of Num. In particular, fromInteger is a joy. But how about lists? For example, if I have data Foo a = F [a] I can create a fromInteger such as fromInteger i = F [fromInteger i] and then a 19::(Foo Int), could become F [19]. Is it

[Haskell-cafe] Unary Minus

2009-04-06 Thread Paul Keir
If I use :info (-) I get information on the binary minus. Is unary minus also a function? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

[Haskell-cafe] Infix tuple comma query (,)

2009-04-06 Thread Paul Keir
module Main where data (:%^) a b = a :%^ bderiving (Show) main = do print $ 18 :%^ (Just 99) print $ (,) 9 10 print $ 9 , 10 The last line in the code above causes a compile error. Why does infix use of the comma (tuple constructor?) function fail without brackets?

RE: [Haskell-cafe] GLUT (glutGet undefined reference)

2009-01-22 Thread Paul Keir
that the information used by ghc-pkg is wrong, and stems from the GLUT package's relationship to libraries known as Xmu and Xi.) Cheers, Paul -Original Message- From: Kazuya Sakakihara [mailto:kaz...@gmail.com] Sent: Thu 22/01/2009 02:14 To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe

[Haskell-cafe] GLUT (glutGet undefined reference)

2009-01-19 Thread Paul Keir
Hi all, I was hoping to introduce my old pal OpenGL with my new chum, Haskell. I used cabal to install GLUT on my 64-bit Ubuntu machine with GHC 6.8.2 (installed via apt-get/synaptic). I followed the wiki OpenGLTutorial1 until: ghc -package GLUT HelloWorld.hs -o HelloWorld at which point my

RE: [Haskell-cafe] forkIO on multicore[MESSAGE NOT SCANNED]

2008-12-23 Thread Paul Keir
Hi Duncan, I'm following the story regarding (parallel) GC in this example with interest, but forgive me if I ask a more minor question regarding your modification of an extra parameter, n, to heavytask. Does this really help (to ensure that each core does work independently)? Surely, with fibs

RE: [Haskell-cafe] forkIO on multicore

2008-12-21 Thread Paul Keir
So this benchmark is primarily a stress test of the parallel garbage collector since it is GC that is taking 75-80% of the time. Note that the mutator elapsed time goes down slightly with 2 cores compared to 1 however the GC elapsed time goes up slightly. Thanks Duncan, Jake et al. I'm more

[Haskell-cafe] forkIO on multicore

2008-12-19 Thread Paul Keir
Hi all, I'm seeing no performance increase with a simple coarse-grained 2-thread code using Control.Concurrent. I compile with: hc conc.hs -o conc --make -threaded and I run with time ./conc +RTS -N2 But using either -N1 or -N2, the program runs in about 1.8secs. (I'd prefer a longer

RE: [Haskell-cafe] forkIO on multicore[MESSAGE NOT SCANNED]

2008-12-19 Thread Paul Keir
Thanks Luke, and everyone else. Ok, back to the drawing board. Paul From: Luke Palmer [mailto:lrpal...@gmail.com] Sent: 19 December 2008 16:44 To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] forkIO on multicore[MESSAGE NOT SCANNED] On Fri, Dec 19, 2008 at 9:27

RE: [Haskell-cafe] forkIO on multicore

2008-12-19 Thread Paul Keir
I did indeed intend for the threads to evaluate before writing to the two variables, thanks. heavytask m = putMVar m $! (fibs !! 10) I now see a time difference, but as you suggested, in the wrong direction (1.5s for one, and 3.6s for two threads). I was hoping for each thread to

[Haskell-cafe] Multi-parameter Type Class

2008-12-11 Thread Paul Keir
Hi all, I've been trying to refactor my tree conversion code to make better use of type classes; and I've discovered multi-parameter type classes and functional dependencies. I have a class with a function a2b, and I'd like map to be used when it's a list of type a. I've created a simple failing

RE: [Haskell-cafe] Multi-parameter Type Class[MESSAGE NOT SCANNED]

2008-12-11 Thread Paul Keir
I took your suggestion and it worked exactly as I had hoped. Thankyou. GHCI (6.8.2) was though a little concerned, and told me I had an: Illegal instance declaration for `ZOT [x] [y]' and recommended I use -fallow-undecidable-instances. I did, and it worked. What have I done though? The word

RE: [Haskell-cafe] Multi-parameter Type Class[MESSAGE NOT SCANNED]

2008-12-11 Thread Paul Keir
Thanks to you both, that also looks fantastic. I'll print it out; put it under my pillow; let it brew overnight and then push in tomorrow ;) -Original Message- From: Thomas DuBuisson [mailto:[EMAIL PROTECTED] Sent: Thu 11/12/2008 15:30 To: Paul Keir Cc: haskell-cafe@haskell.org Subject

[Haskell-cafe] followedBy parser in Parsec

2008-11-27 Thread Paul Keir
Hi, Is there a way in Parsec to check what the next token is, and if it is what you're hoping for, leave it there. This is an example of something which doesn't work at all: testpar = try $ do ae - array_element option [] $ try $ satisfy (\c - c /= '(') unexpected

RE: [Haskell-cafe] followedBy parser in Parsec

2008-11-27 Thread Paul Keir
'lookAhead' is exactly what I needed: try $ array_element = \ae - lookAhead (reservedOp () return ae Many thanks, Paul Maybe you're looking for 'lookAhead'? [...] //Stephan -- Früher hieß es ja: Ich denke, also bin ich. Heute weiß man: Es geht auch so. - Dieter Nuhr

RE: [Haskell-cafe] Searching for ADT patterns with elem and find

2008-11-12 Thread Paul Keir
hit. But I don't think your second (as-pattern) solution for findBs is ugly; I quite like it actually. Cheers, Paul -Original Message- From: Tom Nielsen [mailto:[EMAIL PROTECTED] Sent: Wed 12/11/2008 12:39 To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Searching

[Haskell-cafe] Searching for ADT patterns with elem and find

2008-11-12 Thread Paul Keir
Hi All, If I have an ADT, say data T = A String Integer | B Double | C deriving(Eq) and I want to find if a list (ts) of type T contains an element of subtype B Double, must my containsTypeX function use a second isTypeX function as follows: isTypeB :: T - Bool isTypeB (B _) = True

RE: [Haskell-cafe] Searching for ADT patterns with elem and find

2008-11-12 Thread Paul Keir
/2008 10:23 To: Paul Keir; haskell-cafe@haskell.org Subject: RE: [Haskell-cafe] Searching for ADT patterns with elem and find Hi Paul, maybe False (\x - True) (find isTypeB ts) This can be more neatly expressed as: isJust (find isTypeB ts) But your entire thing can be expressed

[Haskell-cafe] Simple Table Update

2008-10-08 Thread Paul Keir
Hi, I'd like to create a new list based on an original list, using information from a second (symbol) list. That second list should be updated as each element in the new list is added. I've been using map a lot, but that's not an option here, and I'm having trouble obtaining a good recursive

RE: [Haskell-cafe] Simple Table Update

2008-10-08 Thread Paul Keir
) Many thanks, Paul -Original Message- From: Ryan Ingram [mailto:[EMAIL PROTECTED] Sent: Wed 08/10/2008 18:03 To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Simple Table Update Prelude :t Data.List.mapAccumL Data.List.mapAccumL :: (acc - x - (acc, y)) - acc - [x

[Haskell-cafe] One liner?

2008-10-02 Thread Paul Keir
Hi all, There's a common little situation I keep bumping up against. I don't understand where I'm going wrong, so I've made a little example. It's to do with binding a result to a variable name using -. This code works fine: -- module Main where

RE: [Haskell-cafe] One liner?

2008-10-02 Thread Paul Keir
Thanks, and to Ketil too. I did see past the missing ./foo/. That's certainly a solution I'm happy with, and I didn't know the term eta reduction, so thanks for that too. Paul -Original Message- From: Mitchell, Neil [mailto:[EMAIL PROTECTED] Sent: Thu 02/10/2008 16:26 To: Paul Keir

[Haskell-cafe] Pretty Print, text or ++?

2008-08-15 Thread Paul Keir
Hi there, I'm writing a pretty printer using the Text.PrettyPrint library, and there's a pattern I'm coming across quite often. Does anyone know whether, text (a ++ b ++ c ++ d) or text a + text b + text c + text d runs quicker? Cheers, Paul ___

RE: [Haskell-cafe] Pretty Print, text or ++?

2008-08-15 Thread Paul Keir
Thanks, So you're recommending: text (concat [a,b,c,d,e]) Might this not transform my pretty printing into ugly printing; when longer strings are used? Paul -Original Message- From: [EMAIL PROTECTED] on behalf of John Van Enk Sent: Fri 15/08/2008 14:31 To: Paul Keir Cc: haskell-cafe

[Haskell-cafe] RE: Pretty Print, text or ++?

2008-08-15 Thread Paul Keir
Awesome! Thanks to you all. I'll start with hsep[map a, b, c, d] and then I can try changing hsep for other things. Paul -Original Message- From: Benedikt Huber [mailto:[EMAIL PROTECTED] Sent: Fri 15/08/2008 14:53 To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: Pretty Print

RE: [Haskell-cafe] Parsec expressions with alphaNum operators

2008-04-08 Thread Paul Keir
Thanks Chris, When I looked at the Fortran alphaNum operators (.and. .or. etc.) I had hoped that supplying Parsec's opStart with a dot would have been hitting the nail on the head. Oh well. I have noticed something interesting though. If I simply omit the a from opLetter, the problem is gone. In

RE: [Haskell-cafe] Parsec Expected Type

2008-04-07 Thread Paul Keir
Thanks. reservedOp is a better fit; :+ should only be :+. I also overcame my type issues in an ad-hoc manner, adding return () whenever I needed to. -Original Message- From: Tillmann Rendel [mailto:[EMAIL PROTECTED] Sent: 30 March 2008 12:30 To: Paul Keir; haskell-cafe@haskell.org

[Haskell-cafe] Parsec expressions with alphaNum operators

2008-04-07 Thread Paul Keir
; Right ans - print ans } -- code ends Cheers, Paul Keir Research Student University of Glasgow Department of Computing Science [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http

RE: [Haskell-cafe] Parsec Expected Type

2008-03-29 Thread Paul Keir
Many thanks guys, you've really taught me how to catch a fish here! Paul -Original Message- From: Brandon S. Allbery KF8NH [mailto:[EMAIL PROTECTED] Sent: Sat 3/29/2008 1:41 AM To: haskell-cafe@haskell.org Cafe Cc: Paul Keir Subject: Re: [Haskell-cafe] Parsec Expected Type On Mar 28

RE: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Paul Keir
? Paul -Original Message- From: Luke Palmer [mailto:[EMAIL PROTECTED] Sent: Fri 3/28/2008 12:26 AM To: Paul Keir Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Parsec Expected Type Hi Paul, 2008/3/27 Paul Keir [EMAIL PROTECTED]: Hi, Does anyone know why this reduced Parsec

RE: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Paul Keir
better if I ask: Why are 'reserved' and 'symbol' different types? Paul (Haskell Novice) -Original Message- From: Jonathan Cast [mailto:[EMAIL PROTECTED] Sent: Fri 3/28/2008 2:05 PM To: Paul Keir Cc: Luke Palmer; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Parsec Expected Type

RE: [Haskell-cafe] No newlines in the whitespace for Parsec lexeme parsers

2008-03-27 Thread Paul Keir
newlines whenever I need to. Cheers, Paul -Original Message- From: Brandon S. Allbery KF8NH [mailto:[EMAIL PROTECTED] Sent: 26 March 2008 11:48 To: haskell-cafe@haskell.org Cafe; Paul Keir Subject: Re: [Haskell-cafe] No newlines in the whitespace for Parsec lexeme parsers On Mar 26, 2008, at 7

[Haskell-cafe] Parsec Expected Type

2008-03-27 Thread Paul Keir
Hi, Does anyone know why this reduced Parsec production stops compilation, and how I can fix it? tester = reserved parameter | do { reserved dimension; symbol : } Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] No newlines in the whitespace for Parsec lexeme parsers

2008-03-26 Thread Paul Keir
Hi, I'm looking to parse a Fortran dialect using Parsec, and was hoping to use the ParsecToken module. Fortran though is unlike the Parsec examples, and prohibits default line continuation (requiring instead an explicit ampersand token ). The lexical parsers of the ParsecToken module skip

[Haskell-cafe] Parsec (Zero or One of)

2008-03-25 Thread Paul Keir
Hi, I'm having some difficulty using the Parsec library, perhaps you could help. I've reduced my problem as shown below. I would like the 'only_prod' parser to require the reserved string only, _optionally_ followed by an identifier. As part of 'mytest', this should then be followed by the

RE: [Haskell-cafe] Parsec (Zero or One of)

2008-03-25 Thread Paul Keir
Thanks. I can't find optionMaybe in my version 2.1 of Parsec, but in any case, defining my only_prod as only_prod = do { reserved only; option [] identifier } or only_prod = do { reserved only; identifier | return [] } gives the same error responses as before. I will anyway look closer at

RE: [Haskell-cafe] Parsec (Zero or One of)

2008-03-25 Thread Paul Keir
, with string only; whiteSpace; for clarity. Still stuck though... P -Original Message- From: Brandon S. Allbery KF8NH [mailto:[EMAIL PROTECTED] Sent: Tue 25/03/2008 19:58 To: Paul Keir; haskell-cafe@haskell.org Cafe Subject: Re: [Haskell-cafe] Parsec (Zero or One of) On Mar 25, 2008, at 12

RE: [Haskell-cafe] Parsec (Zero or One of)

2008-03-25 Thread Paul Keir
Many thanks. -Original Message- From: Brandon S. Allbery KF8NH [mailto:[EMAIL PROTECTED] Sent: Tue 25/03/2008 20:29 To: Paul Keir; haskell-cafe@haskell.org Cafe Subject: Re: [Haskell-cafe] Parsec (Zero or One of) On Mar 25, 2008, at 16:26 , Paul Keir wrote: Thankyou. Yes, I'd also