[Haskell-cafe] Re: Type classes and type equality
- If we permit overlapping instances extension, then a few lines of code decide equality for all existing and future types: class TypeEq x y b | x y - b instance TypeEq x x HTrue instance TypeCast HFalse b = TypeEq x y b This is exactly what I was after, but it doesn't seem to work in Hugs - even with overlapping instances and unsafe overlapping instances turned on. Hugs is indeed quite problematic; back in 2004 we essentially gave up on Hugs for anything moderately advanced, especially after Ralf found an example which typechecks only if constraints are specified in a particular order. If we permute the constraints (I think, it was in the instance declaration), Hugs complaints. Clearly the order of constraints should not matter. It has been my experience that the code requiring undecidable instances on GHC might not work on Hugs, failing with sometimes bizarre error messages. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] How Albus Dumbledore would sell Haskell
| Simon (aka Dumbledore) is speaking to four different Houses: scientists | (Ravenclaw), engineers (Hufflepuff), entrepreneurs (Slytherin), and | managers (Griffindor). I wish I could live up to this image! Lots of interesting ideas on this thread, and Haskell-Cafe threads are *supposed* to wander a bit. But, just to remind you all: I'm particularly interested in concrete examples (pref running code) of programs that are * small * useful * demonstrate Haskell's power * preferably something that might be a bit tricky in another language I have lots of *general* ideas. What I'm hoping is that I can steal working code for one or two compelling examples, so that I can spend my time thinking about how to present it, rather than on dreaming up the example and writing the code. (But don't let me inhibit wider-ranging discussion as well.) thanks Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] RE: [Haskell] haskell question
[Redirecting to Haskell Cafe] Hi Greg I think it's very likely that you *can* do what you want. I have not taken long enough to understand just what you are trying to do, but I do know why your program is failing, and I think you'll agree it *should* fail. Look at these lines (slightly simplified) class CoreAgentSyntax x where offer :: (CoreProcessSyntax p) = [n] - (p a x) - x data MinimalAgentSyntax nn pp = Concretion [nn] pp instance CoreAgentSyntax (MinimalAgentSyntax nn pp) where offer = Concretion The class decl says that every instance of 'offer' must have type forall p, forall n, forall a. (CoreProcessSyntax p) = [n] - p a x - x where x is the instance type. Not the forall n! Even once x is fixed, we must have a function that is polymorphic in n,p,a But in your instance declaration, offer = Concretion has the type [nn] - pp - MinimalAgentSyntax nn pp No for-alls, because the whole instance decl binds the 'nn'. Hence it's just not polymorphic enough. I'm not sure how to fix your problem. Perhaps you need another argument for CoreAgentSyntax? class CoreAgentSyntax n x where offer :: (CoreProcessSyntax p) = [n] - (p a x) - x instance CoreAgentSyntax nn (MinimalAgentSyntax nn pp) where offer = Concretion now you are in better shape. There's another problem because you use 'p' with kind * in some places and (*-*-*) in others, but thats a separate issue. Oleg is good at this kind of stuff. Simon From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Greg Meredith Sent: 18 April 2007 14:53 To: [EMAIL PROTECTED] Subject: [Haskell] haskell question Haskellians, In the attached file i have implemented the bare bones core of the syntax -- pre structural equivalence -- of Milner's presentation of \pi via abstractions and concretions. (There's a minor twist in that the notion of location affords more structure than in Milner's original presentation which i have added to support an ultimate probabilistic interpretation.) The file compiles with ghc as is. If you uncomment the last section, however, you see that to close the loop on the constraints for the agent syntax we hit a typing error. i think this is a hard constraint in Haskell that prevents this level of generality in the specification, but maybe you can see a way around it. i'm certainly no Haskell expert. Best wishes, --greg P.S. The reason for this level of generality is that with it you can close the loop and form a mutual recursion between the types for the syntax of processes and the type of names -- without having that choice predesigned into the structure of processes (or names). i can do this trick in OCaml with recursive modules, but it's definitely not pretty. i was hoping Haskell could make it pretty. -- L.G. Meredith Managing Partner Biosimilarity LLC 505 N 72nd St Seattle, WA 98103 +1 206.650.3740 http://biosimilarity.blogspot.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] question about Data.Binary and Double instance
On Wed, 2007-04-18 at 21:12 -0700, David Roundy wrote: On Thu, Apr 19, 2007 at 10:20:21AM +1000, Duncan Coutts wrote: and people will for ever be defining newtype wrappers or complaining that the whole library isn't parametrised by the endianness or whatever. For existing formats you need much more flexibility and control. The Binary class is to make it really convenient to serialise Haskell types, and it's built on top of the layer that gives you full control. We intend to work more on this other side of the library in the coming couple of months. If you could tell us a bit more about your use case, that'd be great. I just want to read in a file full of Doubles (written in binary format from C++) and print out text (into a pipe or file to be read by gnuplot). It's not a high-performancs use (the file is only a megabyte or so), but it's something that *ought* to be easy, and so far as I can tell, it requires tricky hackery. Right, it should be simple. With the api I'm hacking on at the moment you just have primitives like (importing Data.Binary.Get as Get): Get.word :: Get Word Get.word8 :: Get Word8 and you'd need: Get.double :: Get Double --IEEE double format As you noticed, that's not a primitive which we have yet. With that it should be really easy to get a sequence of them: Get.run (mapM (const Get.double) [0..n]) :: Lazy.ByteString - [Double] or whatever. I suppose I was just disappointed, because I'd figured that the Binary library was there to do what I wanted. :( It was something I could have done in five minutes (counting tuning the gnuplot file) in perl, and it's embarrassing (which makes it frustrating) to fail in Haskell to complete it in... I couldn't say how long, an hour or so? Yeah, we've concentrated so far on the serialisation of Haskell values, not reading/writing externally defined binary formats. I don't think we've been especially clear on that. But we do intend to tackle both. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel executing of actions
Hi! On 4/18/07, Juan Carlos Arevalo Baeza [EMAIL PROTECTED] wrote: This evaluates all the elements of the list using parMap (the expensive part, right?), and then sequentially applies the action on the current thread. True. But currently I have the main function I would like to parallel something like this: drawPixel x y = do openGLDrawPixel x y color where color = calcColor x y But it is probably really better if I first calculate everything and then just draw it. It is easier to parallelize (will have only pure functions) and also I will not have those OpenGL errors. Thanks everybody Mitar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] How Albus Dumbledore would sell Haskell
G'day all. Quoting Simon Peyton-Jones [EMAIL PROTECTED]: Lots of interesting ideas on this thread, and Haskell-Cafe threads are *supposed* to wander a bit. But, just to remind you all: I'm particularly interested in concrete examples (pref running code) of programs that are * small * useful * demonstrate Haskell's power * preferably something that might be a bit tricky in another language I updated the diff example a bit: http://andrew.bromage.org/darcs/diff/ It now features TWO newtype synonyms. This illustrates a crucial feature of Haskell: Abstractions are cheap. Cheers, Andrew Bromage ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How Albus Dumbledore would sell Haskell
* small * useful * demonstrate Haskell's power * preferably something that might be a bit tricky in another language Something I like: A finite (binary) relation data Rel q = Rel { elems :: [(q,q)] } We do not export constructors, hence rel xs = Rel { elems = xs } Now, the function mirror mirror r = rel [ (p,q) | (q,p) - elems r ] is an involution, that is mirror . mirror == id. Okay, how to exploit that? Nothing easier than that in Haskell: Just make mirror a field of Rel data Rel q = Rel { elems :: [(q,q)], mirror :: Rel q } and change the construction function to rel xs = r where r = Rel { elems = xs , mirror = let m = rel [ (p,q) | (q,p) - elems r ] in m { mirror = r } } Note that the signatures of mirror and rel are the same as before. Try this in your favorite language! Regards, -- -- Mirko Rahn -- Tel +49-721 608 7504 -- --- http://liinwww.ira.uka.de/~rahn/ --- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How Albus Dumbledore would sell Haskell
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 [EMAIL PROTECTED] wrote: I updated the diff example a bit: http://andrew.bromage.org/darcs/diff/ It now features TWO newtype synonyms. This illustrates a crucial feature of Haskell: Abstractions are cheap. Okay, looking at that code: The comments before the type definitions are mostly good... now it looks like I'm going into critique mode :) Range (that is, the comment describing it) needs to say whether it's inclusive of its first and/or its last endpoint (in fact it is inclusive, I can determine by looking at the definition of rangeDist) I suppose Match is the same (inclusive), but I can't tell. And personally I don't know what the significance/meaning of a found match is. Comparing data Range = Range Line Line and type Match = (Line,Line), they are isomorphic, but declared differently (which is fine IMO) With just a little modification, it could use haddock syntax for the comments! I got a little lost reading the code. I think all the data/type definitions should be moved together, to the top. And the comments on the types enhanced a little to make it clearer how the algorithm goes. Or if diff is a weird confusing algorithm even in Haskell, put a more thorough description of why/how it uses those types and/or a reference to a paper on the subject, I would personally like :). Maybe that doesn't show off how clear Haskell itself is, or maybe it gives the reader a better chance of understanding it at all and thereby seeing how straightforward it is. I don't know, are there QuickCheck-style properties we can say about diff? (they are another valuable tool for understanding in detail what the code is supposed to do) The only IO that displayDiff does is putStrLn. It should probably return a string instead (and be called showDiff? would it be necessary to replace the putStrLn IO with some sort of writer monad to keep the code's clarity? or the ShowS-style sequencing/concatenation is (.) and output is (str++) (or, showLn: (\s - str ++ '\n' : s)) -- that can be abstracted so it's not so ugly...) Then, displayDiff = putStr . showDiff Isaac -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGJ09qHgcxvIWYTTURAhqrAJ9SFYmIifl5Ahf0umg0SnImGKr3tgCgwLze bZdTYUzmy+C2uXwFOkJOcdU= =KfVH -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] First order Haskell without Data
Hi, Just a comment or two on the implications of converting higher-order functions to data. The paper you reference about this uses the method of defunctionalization. This is a whole program transformation and might therefore not be suitable in a compiler such as GHC or YHC. On the other hand, it is more or less exactly what JHC uses If you want to support separate compilation you should go for more conventional closure conversion. This is in essence what every compiler which compiles a higher order language does. But if you want to have a typed language which can express this transformation you will be needing quite a sophisticated type system. http://www.cs.cmu.edu/~rwh/papers/closures/popl96.pdf Just my 2 öre. Josef On 4/19/07, Neil Mitchell [EMAIL PROTECTED] wrote: Hi, I've been wondering what is essential to Haskell and what isn't. Not from a point of view of what could be removed from the language, but what could be removed from a Core language. Given the features of higher-order, laziness and data types: Laziness can be converted to higher-order functions Data types can be converted to higher-order functions Higher-order functions can be converted to Data So as far as I can see it we have left: {data-types only} {higher-order functions only} But we don't have laziness only, so my question is if it is possible to represent all of Haskell in a first-order language without data types, but with laziness. If its possible to do so in a strict first-order language without data types, then I'd also be interested. Are any of these known results? Thanks Neil References: * data types - higher order is in Efficient Interpretation by Transforming Data Types and Patterns to Functions http://www.cs.nott.ac.uk/~nhn/TFP2006/Papers/03-JansenKoopmanPlasmeijer-EfficientInterpretation.pdf * laziness - functions, functions - data is in Definitional Interpreters for Higher-Order Programming Languages http://www.brics.dk/~hosc/local/HOSC-11-4-pp363-397.pdf ___ 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] question about Data.Binary and Double instance
Duncan Coutts wrote: Yeah, we've concentrated so far on the serialisation of Haskell values, not reading/writing externally defined binary formats. I don't think we've been especially clear on that. But we do intend to tackle both. Speaking for myself, I certainly didn't realise you were intending to solve these two different problems. Serialisation and binary data access are clearly quite different issues (though it makes sense for the one to layer on the other). Perhaps you should (a) be clearer in your propaganda and (b) give the two parts different names? Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] question about Data.Binary and Double instance
On Thu, 2007-04-19 at 12:23 +0100, Jules Bean wrote: Duncan Coutts wrote: Yeah, we've concentrated so far on the serialisation of Haskell values, not reading/writing externally defined binary formats. I don't think we've been especially clear on that. But we do intend to tackle both. Speaking for myself, I certainly didn't realise you were intending to solve these two different problems. Serialisation and binary data access are clearly quite different issues (though it makes sense for the one to layer on the other). Perhaps you should (a) be clearer in your propaganda and (b) give the two parts different names? Aye, it was possibly a mistake to call it Data.Binary since people interpret that to mean whichever of those two problems that person needs to solve :-). We should rename the Haskell value serialisation part to Data.Binary.Serialise or something. Then you'll have to decide at the point you write your imports which kind of problem you're dealing with, by importing either Data.Binary.Serialise or Data.Binary.Get and .Put. That should help make it clearer to people. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Writing guards shorthand
Support I want to infer the type given an Op that looks like this (incomplete): data Op = Minus | Plus | Mul | LT | GT Is there a shorthand way of bunching Minus, Plus and Mul in a function guard since they all result in TyNum whereas the rest in TyBool? I really don't want several function clauses and neither do I want separate guards for every constructor. Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Writing guards shorthand
Hi isBool x = isLT x || isGT x isNum x = not $ isBool x isLT and isGT can be derived automatically using derve [1], with the Is class (or DrIFT if you want). Thanks Neil [1] google data derive On 4/19/07, Joel Reymont [EMAIL PROTECTED] wrote: Support I want to infer the type given an Op that looks like this (incomplete): data Op = Minus | Plus | Mul | LT | GT Is there a shorthand way of bunching Minus, Plus and Mul in a function guard since they all result in TyNum whereas the rest in TyBool? I really don't want several function clauses and neither do I want separate guards for every constructor. Thanks, Joel -- http://wagerlabs.com/ ___ 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] Writing guards shorthand
This is what want. Notice the succinctness. Objective Caml version 3.10+dev24 (2007-02-16) # type foo = A | B | C | D | E | F ;; type foo = A | B | C | D | E | F # A;; - : foo = A # let infer = function | A | B | C - true; | D | E | F - false;; val infer : foo - bool = fun # infer A;; - : bool = true # infer B;; - : bool = true # infer D;; - : bool = false # infer F;; - : bool = false # -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Writing guards shorthand
Neil Mitchell wrote: Hi isBool x = isLT x || isGT x isNum x = not $ isBool x isLT and isGT can be derived automatically using derve [1], with the Is class (or DrIFT if you want). You can also get a long way with GHC's built in derivations for Eq, Enum and Show. If an Enum instance is possible then you can write something like isBool = (`elem` [LT .. GT]) isNum = (`elem` [Minus .. Mul]) If enum is not possible, because some of the constructors are not nullary, then there is the following cute/ugly hack if you instead derive Show: constrName = takeWhile (/=' ') . show and you can say isBool x = constrName x `elem` [LT,GT] isNum x = constrName x `elem` [Minus,Plus,Mul] What this leads us towards is that it might be rather nice (perhaps even nice enough to build into a compiler) to be able to derive, for each type with multiple constructors, a type 'which is the enumeration of the constructors'. I.e. a type with the same constructors (up to some namespace fix like prepending with C) but all nullary: data Atom = Null | MyInt Int | MyString String derives... data AtomCons = CNull | CMyInt | CMyString deriving (Ord,Eq,Enum,Show) and a function constr :: Atom - AtomCons Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Writing guards shorthand
Joel Reymont wrote: This is what want. Notice the succinctness. # let infer = function | A | B | C - true; | D | E | F - false;; val infer : foo - bool = fun Yes, I appreciate what you want, and I know ocaml too :) I was just talking around the other ways you can achieve it. I don't know if there is a strong reason why haskell doesn't support an equivalent syntax. I'd guess something like: f A = B = C = true f D = E = F = false or perhaps f A = f B = f C = true f D = f E = f F = false Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Writing guards shorthand
Hi Jules, What this leads us towards is that it might be rather nice (perhaps even nice enough to build into a compiler) to be able to derive, for each type with multiple constructors, a type 'which is the enumeration of the constructors'. I.e. a type with the same constructors (up to some namespace fix like prepending with C) but all nullary: data Atom = Null | MyInt Int | MyString String derives... data AtomCons = CNull | CMyInt | CMyString deriving (Ord,Eq,Enum,Show) and a function constr :: Atom - AtomCons If you can derive Enum for all possible constructors (supplying undefined for all fields) then people can do this already: isBool x = fromEnum x `elem` [fromEnum LT .. fromEnum GT] And I'm sure with an elemCtorSet you could automate most of this away in to a tidy little function. As a side note, this is what Derive already does :-) Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] 2 HaXml questions
a) After filtering the content I want to use how do I extract the text? eg a = xtract html/body/h2/- which should return the text contained in the h2 tag. There is a parser called text which returns the text but I don't know how to use it ? Is there a much simpler way I have missed? b) What is a CRef? When are they used? Marc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Writing guards shorthand
Joel Reymont [EMAIL PROTECTED] writes: Support I want to infer the type given an Op that looks like this (incomplete): data Op = Minus | Plus | Mul | LT | GT Is there a shorthand way of bunching Minus, Plus and Mul in a function guard since they all result in TyNum whereas the rest in TyBool? I really don't want several function clauses and neither do I want separate guards for every constructor. Is there some reason why you don't want data Op = Aop Aop | Bop Bop data Aop = Minus | Plus | Mul data Bop = LT | GT or similar? I would agree that it's a shame one cannot just write data Op = Aop (Minus | Plus | Mul) | Bop (LT | GT) or even, given a somewhat different type system, data Op = Aop | Bop where Aop = Minus | Plus | Mul Bop = LT | GT but it would seem reasonable to reflect the different types of the Ops in different types in their representations. -- Jón Fairbairn [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Writing guards shorthand
On Apr 19, 2007, at 4:10 PM, Jón Fairbairn wrote: Is there some reason why you don't want data Op = Aop Aop | Bop Bop data Aop = Minus | Plus | Mul data Bop = LT | GT It's a long story. The short version is that the above will complicate my AST a whole lot. I had it this way before. Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Writing guards shorthand
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jón Fairbairn wrote: Is there some reason why you don't want data Op = Aop Aop | Bop Bop data Aop = Minus | Plus | Mul data Bop = LT | GT or similar? I would agree that it's a shame one cannot just write data Op = Aop (Minus | Plus | Mul) | Bop (LT | GT) or even, given a somewhat different type system, data Op = Aop | Bop where Aop = Minus | Plus | Mul Bop = LT | GT but it would seem reasonable to reflect the different types of the Ops in different types in their representations. Slightly off-topic, I had a problem like this, only where I wanted to classify by more than one dimension: readable? as well as writable? (some were none, some both, some just readable and some just writable), so I couldn't split up the type hierarchically like that. I think I just wrote tedious functions to say whether each constructor was in each category. Isaac -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGJ4uLHgcxvIWYTTURAkKgAJ9N998vRVsmrhHuz/zoVJaHN3nuKgCcCSmX qRFWGfKZGORAKI61J8153AI= =eVR6 -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] fftw bindings
Hi everybody, I was wondering if someone had fftw bindings for haskell, or if I should roll my own. I did a small search but found nothing. Fawzi ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] COM and Haskell
All, I'm interested in automating Excel using Haskell. I'm writing a little program for my wife and it'd be nice to fill out an Excel spreadsheet for her (with formatting so I don't think CSV will cut it). A bit of Googling didn't turn up anything interesting. Has any work been done on using Excel (or more generally, COM) from Haskell? Thanks for any pointers! Justin p.s. I'm aware of the article Spreadsheet for Functional Programmers article and Neil Mitchell's post about HsExcel - but those go the wrong way :( ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Morphing ASTs and scrapping boilerplate code
Folks, I'm transforming ASTs as part of my compiler from one language into another. The source AST is a list of statements whereas the target AST is a class definition. type Object a = State Obj a data Obj = Object { objSym :: Integer -- starting # for gensym , objVars :: M.Map String VarDecl , objProps :: M.Map String PropDecl , objMeths :: M.Map String MethodDecl } deriving (Show, Eq) I'm using a state monad and the transformations are supposed to update the state (object) as needed to add variables, methods, etc. class Morpher a b | a - b where morph :: a - Object b I have a lot of boilerplate code like this and wonder how I can scrape it. instance Morpher Type C.Type where morph TyInt = return C.TyInt morph TyFloat = return C.TyFloat morph TyStr = return C.TyStr morph TyBool = return C.TyBool morph TyColor = return C.TyColor morph TyStyle = return C.TyStyle morph (TyList ty) = liftM C.TyList (morph ty) morph (TyArray ty) = liftM C.TyArray (morph ty) morph (TySeries ty) = liftM C.TySeries (morph ty) morph (TyInput ty) = liftM C.TyProp (morph ty) morph (TyRef ty) = liftM C.TyRef (morph ty) morph TyUnit = return C.TyUnit morph TyPrintDest = return C.TyPrintDest Notice that I'm calling a constructor of the same name in a different module ... unless it's an exception. instance Morpher BackRef C.Expr where morph Now = C.Int 0 morph (BarsBack e) = morph e instance Morpher DataRef C.Expr where morph (DS x) = C.Int x How can I reduce the boilerplate here? Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] fftw bindings
On Thu, Apr 19, 2007 at 05:37:05PM +0200, Fawzi Mohamed wrote: I was wondering if someone had fftw bindings for haskell, or if I should roll my own. Not that I'm aware of, but if you roll your own, please make them public, as I'll be interested in fftw bindings before long. -- David Roundy http://www.darcs.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Morphing ASTs and scrapping boilerplate code
Just to clarify, I really liked the SYB solution to my previous issue with stripping token locations. It looked like this: strip :: (Data a) = a - a strip = everywhere (mkT f) where f (TokenPos a _) = a f x = x In the general AST transformation case, my constructor name is the same and so is the number of arguments. So, yes, it's a different type but it's a derivative of Data and Typeable just like the original type. Conceptually, I want to lookup the new type from a given module, using the same constructor name as the original type. Then I want to apply morph to every argument of the source constructor and give the resulting values to the new constructor. Lastly, I would like to write pattern matches for special cases (see TokenPos above) and write out the transformation by hand. My ASTs are quite large and there aren't that many special cases. Thanks, Joel On Apr 19, 2007, at 5:11 PM, Joel Reymont wrote: instance Morpher Type C.Type where ... morph (TyList ty) = liftM C.TyList (morph ty) morph (TyArray ty) = liftM C.TyArray (morph ty) morph (TySeries ty) = liftM C.TySeries (morph ty) morph (TyInput ty) = liftM C.TyProp (morph ty) morph (TyRef ty) = liftM C.TyRef (morph ty) morph TyUnit = return C.TyUnit morph TyPrintDest = return C.TyPrintDest -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Morphing ASTs and scrapping boilerplate code
Joel Reymont wrote: I have a lot of boilerplate code like this and wonder how I can scrape it. instance Morpher Type C.Type where morph TyInt = return C.TyInt morph TyFloat = return C.TyFloat morph TyStr = return C.TyStr morph TyBool = return C.TyBool morph TyColor = return C.TyColor morph TyStyle = return C.TyStyle morph (TyList ty) = liftM C.TyList (morph ty) morph (TyArray ty) = liftM C.TyArray (morph ty) morph (TySeries ty) = liftM C.TySeries (morph ty) morph (TyInput ty) = liftM C.TyProp (morph ty) morph (TyRef ty) = liftM C.TyRef (morph ty) morph TyUnit = return C.TyUnit morph TyPrintDest = return C.TyPrintDest One option is to change your data types. I would suggest something like this: data Type = TyPrim TyPrim | TyCon TyCon Type data C.Type = C.TyPrim TyPrim | C.TyCon TyCon C.Type where TyPrim and TyCon (primitves and constructors) can be shared: data TyPrim = TyInt | TyString | TyFloat | TyBool | etc. data TyCon = TyList | TyArray | TySeries | TyInput | TyRef Now the class instance can be: instance Morpher Type C.Type where morph (TyPrim p) = return (C.TyPrim p) morph (TyCon c t) = C.TyCon c $ morph t -- or liftM for people not so in love with Applicative :) Twan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] COM and Haskell
On Thu, Apr 19, 2007 at 08:59:17AM -0700, Justin Bailey wrote: All, I'm interested in automating Excel using Haskell. I'm writing a little program for my wife and it'd be nice to fill out an Excel spreadsheet for her (with formatting so I don't think CSV will cut it). A bit of Googling didn't turn up anything interesting. Has any work been done on using Excel (or more generally, COM) from Haskell? Thanks for any pointers! Justin p.s. I'm aware of the article Spreadsheet for Functional Programmers article and Neil Mitchell's post about HsExcel - but those go the wrong way :( There is only one library: hdirect. But I don't know its status there have been some posts and some authors may have chnaged it. I'd suggest grepping some mailinglist archives (you can find them all on haskell.org) or wait till someone else gives a more helpful reply ;) If you application will be only small you'll be faster using VBScript. Marc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] COM and Haskell
On 19/04/07, Marc Weber [EMAIL PROTECTED] wrote: There is only one library: hdirect. But I don't know its status there have been some posts and some authors may have chnaged it. I'd suggest grepping some mailinglist archives (you can find them all on haskell.org) or wait till someone else gives a more helpful reply ;) I tried quite a while ago to build hdirect, and failed. It looked like it didn't quite support the then-current GHC (6.2???) As far as I can tell, the library hasn't been updated since, so I doubt there's much hope. I'd love to be proved wrong... If you application will be only small you'll be faster using VBScript. Or Python or Perl, or (probably, I'm not sure) Ruby. Or likely many others. Sad, but true... Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] COM and Haskell
Hi I'm interested in automating Excel using Haskell. I'm writing a little program for my wife and it'd be nice to fill out an Excel spreadsheet for her (with formatting so I don't think CSV will cut it). A bit of Googling didn't turn up anything interesting. Does she need to manipulate the spread sheet afterwards? If not, you'd be much better off producing an HTML table. You may also want to see exactly what Excel can do when reading in a formatted HTML table, it may give you CSV+formatting quite easily. If you application will be only small you'll be faster using VBScript. VBA, not VBScript. VB 6 is the standalone programming language, VBA is VB 6 with an API for Excel/Word/Office. VBScript is a scripting version of VB, which should never be used (use JScript instead - its more portable). And I would recommend using VBA, I've done loads of Excel programming - VBA is perfectly easy enough, the hard bit is the Excel API which is quite big. If you move to Haskell you get a slightly better programming language, with the same huge API, at the cost of a painful translation layer to the API. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] COM and Haskell
Hi If you application will be only small you'll be faster using VBScript. Or Python or Perl, or (probably, I'm not sure) Ruby. Or likely many others. No, VBA only. VBA is integrated with Excel and can talk to all the Excel data structures, be developed inside the Excel program etc. It can be saved with a .xls file, install toolbar buttons etc. No other language can do that without painful hoop jumping. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] COM and Haskell
On Thu, Apr 19, 2007 at 06:18:24PM +0100, Neil Mitchell wrote: No, VBA only. I had VBA in mind but typed the wrong name. Thanks Neil for correcting my statement. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How Albus Dumbledore would sell Haskell
Simon Peyton-Jones simonpj at microsoft.com writes: But, just to remind you all: I'm particularly interested in concrete examples (pref running code) of programs that are * small * useful * demonstrate Haskell's power * preferably something that might be a bit tricky in another language I have something that I think nearly fits the bill. Unfortunately, I don't think it quite works because it's a bit specialised. However, I think it suggests a possible area to look, which I'll mention at the end. It's a theorem prover for intuitionistic propositional logic: http://www.polyomino.f2s.com/david/haskell/gentzen.html It's much shorter in Haskell than it would be in other languages. (It's even shorter than the ML that I based it on, because of some shortcuts I can take using lazy evaluation.) Strengths of Haskell that it demonstrates are: * How easy it is to define datatypes (eg trees), and manipulate them using pattern matching, with constructors, Eq, Show coming for free. * How lazy evaluation reduces code length by letting you write code that looks like it would do too much, and then lazy evaluate it (in the proof function) * The ability to extend the syntax with new symbolic operators * Use of higher order functions to simplify code (the (+++) operator) The problem is that I think Gentzen systems are a bit obscure. But I think you could probably show most of the same strengths of Haskell in something similar: game search, eg alpha-beta algorithm. Another advantage of doing game search would be that you'd get to show off persistent data structures (so that when you make a move in lookahead, you don't need to make a copy of the game state, because when you update the game state the old state still persists). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] fftw bindings
On Thu, Apr 19, 2007 at 09:20:36 -0700, David Roundy wrote: On Thu, Apr 19, 2007 at 05:37:05PM +0200, Fawzi Mohamed wrote: I was wondering if someone had fftw bindings for haskell, or if I should roll my own. Not that I'm aware of, but if you roll your own, please make them public, as I'll be interested in fftw bindings before long. For us less knowledgable, what's fftw? /M (curious) -- Magnus Therning (OpenPGP: 0xAB4DFBA4) [EMAIL PROTECTED] Jabber: [EMAIL PROTECTED] http://therning.org/magnus pgpWO6RjmWodI.pgp Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: fftw bindings
Magnus Therning wrote: On Thu, Apr 19, 2007 at 09:20:36 -0700, David Roundy wrote: On Thu, Apr 19, 2007 at 05:37:05PM +0200, Fawzi Mohamed wrote: I was wondering if someone had fftw bindings for haskell, or if I should roll my own. Not that I'm aware of, but if you roll your own, please make them public, as I'll be interested in fftw bindings before long. For us less knowledgable, what's fftw? Fastest Fourier Transform in the West. http://www.fftw.org/ Its cool, they use generative programming: an OCaml program generates codlets in C that can be composed and tuned to the specifics of your machine, then compiled into a blazingly fast FFT/DFT library. /M (curious) ___ 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] Re: How Albus Dumbledore would sell Haskell
A theorem prover might be a really cool example, but if there's one person in the audience that cares then Simon is lucky. :) You need to have examples that people can recognize and see the utility of. -- Lennart On Apr 19, 2007, at 20:48 , DavidA wrote: Simon Peyton-Jones simonpj at microsoft.com writes: But, just to remind you all: I'm particularly interested in concrete examples (pref running code) of programs that are * small * useful * demonstrate Haskell's power * preferably something that might be a bit tricky in another language I have something that I think nearly fits the bill. Unfortunately, I don't think it quite works because it's a bit specialised. However, I think it suggests a possible area to look, which I'll mention at the end. It's a theorem prover for intuitionistic propositional logic: http://www.polyomino.f2s.com/david/haskell/gentzen.html It's much shorter in Haskell than it would be in other languages. (It's even shorter than the ML that I based it on, because of some shortcuts I can take using lazy evaluation.) Strengths of Haskell that it demonstrates are: * How easy it is to define datatypes (eg trees), and manipulate them using pattern matching, with constructors, Eq, Show coming for free. * How lazy evaluation reduces code length by letting you write code that looks like it would do too much, and then lazy evaluate it (in the proof function) * The ability to extend the syntax with new symbolic operators * Use of higher order functions to simplify code (the (+++) operator) The problem is that I think Gentzen systems are a bit obscure. But I think you could probably show most of the same strengths of Haskell in something similar: game search, eg alpha-beta algorithm. Another advantage of doing game search would be that you'd get to show off persistent data structures (so that when you make a move in lookahead, you don't need to make a copy of the game state, because when you update the game state the old state still persists). ___ 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] How Albus Dumbledore would sell Haskell
G'day all. Quoting Isaac Dupree [EMAIL PROTECTED]: Okay, looking at that code: The comments before the type definitions are mostly good... now it looks like I'm going into critique mode :) BTW, for the record, I didn't try too hard with this. It is meant to be illustrative of what you can do with Haskell and not too much time to spare. I didn't haddock-ise the comments because Diff isn't a library. The comments are meant to be more commentary (this is a tutorial, remember!) than developer documentation. Range (that is, the comment describing it) needs to say whether it's inclusive of its first and/or its last endpoint (in fact it is inclusive, I can determine by looking at the definition of rangeDist) Fair point. I suppose Match is the same (inclusive), but I can't tell. And personally I don't know what the significance/meaning of a found match is. OK, this needs explanation. A Match is a match _between_ the two files being diffed. So (a,b) means that line a in file 1 matches line b in file 2. I'll note that, thanks. Comparing data Range = Range Line Line and type Match = (Line,Line), they are isomorphic, but declared differently (which is fine IMO) Yup. They only have to be different enough to cause a type error if you accidentally try to mix them. The only IO that displayDiff does is putStrLn. It should probably return a string instead [...] Possibly, or even use a Writer monad. I habitually use putStrLn, though, because I regularly program in multiple languages, and this way I don't have to remember how Haskell handles line termination on different platforms. Cheers, Andrew Bromage ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: fftw bindings
On Thu, Apr 19, 2007 at 05:46:49PM -0400, Al Falloon wrote: For us less knowledgable, what's fftw? Fastest Fourier Transform in the West. http://www.fftw.org/ Its cool, they use generative programming: an OCaml program generates codlets in C that can be composed and tuned to the specifics of your machine, then compiled into a blazingly fast FFT/DFT library. But that's only the beginning of the coolness! fftw uses runtime timings to optimize each fourier transform based on the behavior of the computer on which it is being run--its cache, memory speed, CPU, etc. The result being that fftw using portable C can beat out most hand-optimized fftw libraries written in assembly! Steven (one of fftw's two authors) has done some incredible work on optimizations. The most unbelievable (to me) was that by eliminating negative constants from the generated code (using subtraction instead) they sped up the library on a particular architecture by some some significant margin (I think I recall 20%). -- David Roundy http://www.darcs.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] COM and Haskell
I hate to recommend Java to Haskellers, but there is a project named Poi at Apache's Jakarta site[1] that will allow you to (with some Java programming) read, write, and manipulate Excel files directly. You don't have to COM to Excel, you don't even need Excel installed! Nice for producing spreadsheets for download from a web-based app on the fly. It is complete enough to do formatting, formulas, and such, but you can see the ugly internals of the Microsoft file formats bleeding out, or at least that was true 4 years ago. Maybe it would be a nice project to create a Haskell version of Poi. --doug [1] http://jakarta.apache.org/poi/ On 4/19/07, Paul Moore [EMAIL PROTECTED] wrote: On 19/04/07, Marc Weber [EMAIL PROTECTED] wrote: There is only one library: hdirect. But I don't know its status there have been some posts and some authors may have chnaged it. I'd suggest grepping some mailinglist archives (you can find them all on haskell.org) or wait till someone else gives a more helpful reply ;) I tried quite a while ago to build hdirect, and failed. It looked like it didn't quite support the then-current GHC (6.2???) As far as I can tell, the library hasn't been updated since, so I doubt there's much hope. I'd love to be proved wrong... If you application will be only small you'll be faster using VBScript. Or Python or Perl, or (probably, I'm not sure) Ruby. Or likely many others. Sad, but true... Paul. ___ 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] COM and Haskell
There are also equivalent libraries (for producing xls files without excel) for python: http://sourceforge.net/projects/pyexcelerator http://sourceforge.net/projects/pyxlwriter/ perl: http://search.cpan.org/dist/Spreadsheet-WriteExcel/ so you don't have to use java... Tim -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Doug Kirk Sent: Friday, 20 April 2007 12:46 PM To: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] COM and Haskell I hate to recommend Java to Haskellers, but there is a project named Poi at Apache's Jakarta site[1] that will allow you to (with some Java programming) read, write, and manipulate Excel files directly. You don't have to COM to Excel, you don't even need Excel installed! Nice for producing spreadsheets for download from a web-based app on the fly. It is complete enough to do formatting, formulas, and such, but you can see the ugly internals of the Microsoft file formats bleeding out, or at least that was true 4 years ago. Maybe it would be a nice project to create a Haskell version of Poi. --doug [1] http://jakarta.apache.org/poi/ On 4/19/07, Paul Moore [EMAIL PROTECTED] wrote: On 19/04/07, Marc Weber [EMAIL PROTECTED] wrote: There is only one library: hdirect. But I don't know its status there have been some posts and some authors may have chnaged it. I'd suggest grepping some mailinglist archives (you can find them all on haskell.org) or wait till someone else gives a more helpful reply ;) I tried quite a while ago to build hdirect, and failed. It looked like it didn't quite support the then-current GHC (6.2???) As far as I can tell, the library hasn't been updated since, so I doubt there's much hope. I'd love to be proved wrong... If you application will be only small you'll be faster using VBScript. Or Python or Perl, or (probably, I'm not sure) Ruby. Or likely many others. Sad, but true... Paul. ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: How Albus Dumbledore would sell Haskell
DavidA wrote: Simon Peyton-Jones simonpj at microsoft.com writes: But, just to remind you all: I'm particularly interested in concrete examples (pref running code) of programs that are * small * useful * demonstrate Haskell's power * preferably something that might be a bit tricky in another language I have something that I think nearly fits the bill. Unfortunately, I don't think it quite works because it's a bit specialised. However, I think it suggests a possible area to look, which I'll mention at the end. It's a theorem prover for intuitionistic propositional logic: http://www.polyomino.f2s.com/david/haskell/gentzen.html It's much shorter in Haskell than it would be in other languages. (It's even shorter than the ML that I based it on, because of some shortcuts I can take using lazy evaluation.) Strengths of Haskell that it demonstrates are: * How easy it is to define datatypes (eg trees), and manipulate them using pattern matching, with constructors, Eq, Show coming for free. * How lazy evaluation reduces code length by letting you write code that looks like it would do too much, and then lazy evaluate it (in the proof function) * The ability to extend the syntax with new symbolic operators * Use of higher order functions to simplify code (the (+++) operator) The problem is that I think Gentzen systems are a bit obscure. But I think you could probably show most of the same strengths of Haskell in something similar: game search, eg alpha-beta algorithm. Another advantage of doing game search would be that you'd get to show off persistent data structures (so that when you make a move in lookahead, you don't need to make a copy of the game state, because when you update the game state the old state still persists). Game search is exactly an example use in Why Functional Programming Matters (http://www.math.chalmers.se/~rjmh/Papers/whyfp.html). That paper, 23 years later, is still pretty compelling. Perhaps, it should just be modernized and somewhat expanded. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe