Re: [Haskell-cafe] Quasi quotation question
Sure. Just use http://hackage.haskell.org/package/haskell-src-meta-0.0.6. You are probably interested in parsePat or parseExp. I've used parseExp in a package. -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] [ANNOUNCE] text-xml-qq - XML quasiquoter for Text.XML.Light
Hi, I've just released the first version of text-xml-qq, It's a Template Haskell quasiquoter that converts XML code into Text.XML.Light.Element compile time. Feature requests, bug fixes etc are welcomed. The package only got one backend (xml-package) at the moment but it should be trivial to add more backends (e.g. for a bytestring-based xml package). You can embed Haskell variables in the xml code. Inside xml-elements you use the syntax {foo} for embedded variables. If you wish to embed an element or text you use the syntax foo. See example or the test-file http://github.com/finnsson/text-xml-qq/blob/master/src/Text/XML/TestQQ.hs at the project site http://github.com/finnsson/text-xml-qq. -- Oscar === Example === Given the variables url = google.se elem = gmail attrNs = something attrName = Pelle attrValue = Arne elemCont = CRef testing cont1 = Elem $ blank_element { elName = QName hej Nothing Nothing } cont2 = CRef other test the code [$xmlQQ| {url}:{elem} {attrNs}:{attrName}={attrValue} attr=cool elem ns1:elem1=1 ns2:elem2=2elemCont/elem elem / el / cont1 cont2 /{url}:{elem} |] will generate the data structure element { elName = QName elem Nothing (Just url), elAttribs = [Attr (QName attrName Nothing (Just attrNs)) attrValue, Attr (qname attr) cool], elContent = [ (Elem $ blank_element { elName = QName elem Nothing Nothing, elAttribs = [Attr (QName elem1 Nothing (Just ns1)) 1, Attr (QName elem2 Nothing (Just ns2)) 2], elContent = [elemCont] }), (Elem $ blank_element { elName =QName elem Nothing Nothing}), (Elem $ blank_element { elName = QName el Nothing Nothing}), cont1, cont2] } === End example === ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Function signatures and type class constraints
Thanks for the tip. You saved my day (and code)! So what is the point of having the constraint on the left side of the '='? Will it allow me to do anything that the right-side constraint won't? -- Oscar On Mon, Aug 23, 2010 at 11:06 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: On Monday 23 August 2010 22:30:03, Oscar Finnsson wrote: Hi, I'm wondering why I have to repeat the class constraints at every function. If I got the data type data (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data c) = Foo a b c = Foo a b c Type class constraints on datatypes are considered a wart. They don't do what people expect, in particular they don't make the constraints available at the use site. It works if you move the constraints across the '=': {-# LANGUAGE ExistentialQuantification #-} data Foo a b c = (Eq a, Show a, ...) = Foo a b c or with GADT syntax: {-# LANGUAGE GADTs #-} data Foo x y z where Foo :: (Eq a, Show a, ...) = a - b - c - Foo a b c Both make the constraints available at the use site, bar :: Foo a b c - String bar (Foo a b c) = Foo ++ show a ++ ++ show b ++ ++ show c ++ , Yay! and then a function from Foo to String I have to supply the signature bar :: (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data c) = Foo a b c - String even though it should be clear that a, b and c *must* fulfill the constraints already so I should be able to just supply the signature One would think so. It's a wart. bar :: Foo a b c - String ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Function signatures and type class constraints
Hi, I'm wondering why I have to repeat the class constraints at every function. If I got the data type data (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data c) = Foo a b c = Foo a b c and then a function from Foo to String I have to supply the signature bar :: (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data c) = Foo a b c - String even though it should be clear that a, b and c *must* fulfill the constraints already so I should be able to just supply the signature bar :: Foo a b c - String Another related problem I got is that even though I can create the type type B = (Eq a, Show a, Data a, Eq b, Show b, Data b, Eq c, Show c, Data c) = Foo a b c I cannot use it like bar :: B - String so my type class constraints got a tendency become huge! It is possible to work around this somehow? I'm in a situation at the moment where I got a data type with four fields each with three constraints (Show, Eq, Data), so I have to repeat 12 constraints at every function signature... :( Finally is there some way to bundle type class constraints, something like data {Eq, Show, Data} {a, b, c} = Foo a b c = Foo a b c -- make believe syntax so I don't have to repeat every constraint and variable all the time? -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: text-json-qq 0.2.0 (now with haskell-src-meta goodness)
Hi, I've just uploaded a new version of text-json-qq, the json quasiquoter. Now it's possible (thanks to haskell-src-meta) to insert Haskell code inside the qq-code: myCode = [$jsonQQ| {age: | age + 34 :: Integer |, name: | map toUpper name |} |] where age = 34 :: Integer name = Pelle For further info read the documentation at http://hackage.haskell.org/package/text-json-qq or read/fork the source code at http://github.com/finnsson/text-json-qq -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional dependencies and Peano numbers (and hoogle-bug?)
Thanks for the great feedback. The bijective example was especially interesting. While reading Fun with Type Functions I notices GNum as an interesting alternative to the Num type class but I couldn't find any such package on hackagedb. Do anyone know if there is anything like GNum on hackagedb? On an unrelated note: I hoogled to (i.e. http://haskell.org/hoogle/?hoogle=to) and just got a blank page. Nothing. Nil (not even html.../html). Is this a bug or a feature? :) The reason I hoogled it was because I'm searching for something like explicit casting found in many other languages, something similar to class To f t where to :: f - t instance To a a where to x = x instance (Real a, Fractional b) = To a b where to = realToFrac instance (Read a) = To String (Maybe a) where to = maybeRead -- not from cgi :) so I can write something like (23.2 `to`) :: Maybe Double or ((42 :: Integer) `to`) :: Float Anyone made a module/package that solves this problem already? I cannot be the first that needs generic type safe conversion... . -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Merge hsql and HDBC -- there can only be one!
I'd love to see this too. I've only used HDBC and I think it works well. A common problem in the Haskell-community is that some produce low-level bindings/libs and some produce high-level (extremely type safe) bindings/libs but there's seldom good support for switching between or combining the two approaches. My experience is that when it comes to real world scenarios involving databases/xml/json/c you are seldom able to figure out *all* types compile time and are thus forces to use the low-level lib for everything even though you got the types (e.g. of a table/view/function/...) at compile time for 90% of your code. That's a shame and something that I wish a merging between the packages would be able to solve. In other words: a good package should support more than one way to interface with the db and the different ways should be possible to seamlessly combine. My wish-list: * low level capabilities a la HDBC * high level capabilities (matching result sets to data types, db functions - haskell type classes or similar) * sql 2003/2008-, pl/sql-quasi quoter * code generation given a db schema. * schema generation from code (i.e. the opposite from the above). * fixture generation (Haskell - db, db - Haskell) * syb-support * BSD3 or DWTFYWT * github :) I'm prepared to spend a couple of hours a week helping out and I got some experience developing database layers that's used in telecom, gaming and logistics. -- Oscar P.S. I'm not saying that there should be only one; competition is always good. It would however be lovely if the community made an effort to (a) produce an package that can cover mosts needs that (b) most developers/package-maintainers used that (c) other developers can build upon with new features. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Functional dependencies and Peano numbers
Hi, there is a lot of buzz around functional dependencies on the mailing list and Planet Haskell. I've read some of the tutorials and I think I understand how they work but I still haven't figured out where they can be useful. * Can someone give me a real world (preferably hackagedb) example where functional dependencies are used? * Can someone give me a real world (preferably hackagedb) example where Peano numbers a la data Zero; data Succ n are used? Finally... * All the examples involving functional dependencies are on the form a b c | a b - c but can they also be on a form similar to a b c d e f g h| b c - d e f | b d g - h (i.e. d,e,f are decided by the b,c-combination while h is decided by the b,d,g-combination)? -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: text-json-qq - json quasiquatation
Hi, I've just uploaded the first version of text-json-qq (http://hackage.haskell.org/package/text-json-qq). It's a quasiquatation library converting json into Haskell (Text.JSON). You can use it like: user = [$jsonQQ| {name: Pelle, age: 34.3, likes: [mac, Haskell] } |] or you can use Haskell variables with the x-syntax like: user = [$jsonQQ| {name: name, age: age} |] name = Pelle age = 34 :: Integer It seems to have some performance problems at the moment so I guess I'll have to learn how to profile my code. -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Announce: hs2dot 0.1.1 - generate graphviz code by analyzing Haskell source code files
It's a small tool that lets you automatically generate graphviz/dot code that visualize the relations between data types, types and type classes. This sounds very familiar to my SourceGraph package that's already on Hackage... I hope that some friendly competition can spur both of us to deliver even better tooling :) You, however, also add the type signatures to your graph; I have the sneaking suspicion that this could get too noisy if you also try to visualise functions in a large module. Visualizing every aspect is probably never a good idea. At the moment I'm sketching on alternative visualizations where only relations between modules show up or where the data constructors for data types aren't visualized. On a related note: has anyone yet tried to visualize the flow of the IO monad in an application? -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Announce: hs2dot 0.1.1 - generate graphviz code by analyzing Haskell source code files
On a related note: has anyone yet tried to visualize the flow of the IO monad in an application? You mean a control flow graph? Exactly. In (most) other programming languages it would be impossible for a tool to automatically know which flow to concentrate on/visualize but in Haskell it should be at least theoretically possible to inspect a package/module and trace the IO monad (beginning in main for an executable) in the code and visualize it as a control flow graph. I think it would probably be a great tool that would help one to inspect the architecture. -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Announce: hs2dot 0.1.1 - generate graphviz code by analyzing Haskell source code files
Hi, I've just released hs2dot on hackagedb. It's a small tool that lets you automatically generate graphviz/dot code that visualize the relations between data types, types and type classes. Example usage: hs2dot Hack.hs | dot -T pdf -o Hack.pdf Multiple files can be analyzed together as in hs2dot Foo.hs Bar.hs | dot -T png -o FooBar.png so their data types can point to each other. Example diagrams generated using h2dot can be found at http://github.com/finnsson/hs2graphviz/tree/master/Examples/ Examples of real code analyzed: http://github.com/finnsson/hs2graphviz/raw/master/Examples/Control.pdf (from hpage) http://github.com/finnsson/hs2graphviz/raw/master/Examples/Hack.png (from Hack) Example of mock code analyzed: http://github.com/finnsson/hs2graphviz/raw/master/Examples/TestCode.pdf (three files analyzed together) The tool is still far from complete. Better handling of algebraic data types and instance declarations are a must. GADTs, data families and type synonym families are not yet implemented so they wont turn up. -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Code review of text-xml-generic
Hi, I've been working on a (de)serialization package from/to XML (using SYB) and wondering if anyone feels like giving me a quick code review before I upload it to hackagedb. The source code can be found at http://github.com/finnsson/Text.XML.Generic It is *heavily* inspired by Text.JSON.Generic. The three files DataEx.hs (slightly modified version of Olegs code), ExGeneric.hs and ExTestGeneric.hs are not part of the package yet since I haven't got the deserialization to work for existentials yet (but I haven't given up!). I plan to upload the package to hackagedb by the end of this weekend so any comments before (and after) are more than welcome. -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: SYB with Existentials
OK. That was probably the most complete answer ever. Under what license are you releasing DataEx.hs? I'm wondering if I may use it in my package (under BSD3 license) until something like it is included in SYB. Pedro: How are extensions to SYB handled? code.google only seems to handle issues - not tickets. -- Oscar On Wed, May 26, 2010 at 8:31 AM, o...@okmij.org wrote: The only, non-fatal, problem is _not_ with writing the instance of gunfold. Defining gunfold is easy. The problem is that the existing SYB -- or, the module Data/Data.hs to be precise -- has non-extensible constructor and datatype descriptions (Constr and DataType). The problem is not fatal and can be worked around in various inelegant ways. Alternatively, one can fix the problem once and for all by making DataType and Constr extensible -- along the lines of the new Exceptions. The following file http://okmij.org/ftp/Haskell/DataEx.hs demonstrates one such fix. The file DataEx.hs also tries to avoid the overlap with Data.Typeable. (One doesn't need to carry the name of the datatype's type constructor in DataType. That name can be obtained from the result of typeOf). The file DataEx can be used alongside the original Data.hs. The code below uses DataEx in that way, to complement Data.hs. The hope is that the maintainers of SYB might choose to extend Data.hs -- perhaps using some bits or ideas from DataEx.hs. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [ANNOUNCE] SyntaxMacros-0.1
We are pleased to announce the first release of SyntaxMacros [1]. Very interesting. This is something I've been interested in since I first heard of Ziggurat. In which order do you recommend I try to learn the packages: HList - AspectAG - SyntaxMacros? I tried to read the SyntaxMacros-paper but had a hard time understanding which parts belonged to the package and which parts belonged to your new mini-language. Do you got the mini-language as a separate download? You mention in the paper that the source of the paper is in literate Haskell and that the code is available but I can't find it at the wiki. I found some code (Expr.hs, Main.hs) in the examples-folder in the packages source code (SyntaxMacrox-0.1.tar.gz) but it doesn't seem to match 1:1 to the code in the paper (couldn't for example find extSpecChars in the paper or updateFinalEnv in the source code). -- Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Existentials and SYB [Was: GADTs and Scrap your Boilerplate]
enDataI :: (Int - DataBox) enDataI = DataBox enDataB :: (Bool - DataBox) enDataB = DataBox instance Data DataBox where gfoldl k z (DataBox d) = z DataBox `k` d gunfold k z c = (if True then k (z enDataI) else k (z enDataB)) Interesting solution but I'm not smart enough to see how the solution can be generalized to any data type that's an instance of Data. Do I have to repeat the if then else for every instance of the Data type class (which I can't) or is there some other way? Oscar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GADTs and Scrap your Boilerplate
Hi, thanks for all the great feedback. Your GADT encodes an existential datatype. The closest attempt to encode existential types in (something like) SYB that I know of is in Section 5.3 of Alexey's PhD thesis [1]. Having said that, he uses the spine view, which makes the generic view in SYB explicit, but this has never been packaged as a library. So I'm afraid the answer is no. The link above might still be useful for your understanding of why this is a complex problem, though. Interesting paper by Alexey. Especially p. 106. Have you tried using StandaloneDeriving (and DeriveDataTypeable)? Thanks for the tip. Didn't know about this feature before but unfortunately it didn't help me. Standalone deriving gave the same error message so I guess it generates similar code to what I wrote. forall d. gunfold k z c = k (z (DataBox::d-DataBox d)) Didn't work either. :( Also why isn't the paramater c used? I guess c says which constructor is used, but since I know which constructor is used (since DataBox only got one) the variable is discarded. However, I remember the solution: I created a function to convert the GADT into another, unGADT type, Is this possible for existential data types too? I tried to convert DataBox to a data type DataBox' a but I couldn't get it to compile. Are there any libraries for generics/reflection that can handle existential data types? EMGM/multirec/? Until I manage to figure this out I'll go with the technique described in http://okmij.org/ftp/Computation/Existentials.html where instead of exposing a function decodeUnknownXML :: String - Maybe DataBox the package expose a function decodeUnknownXML :: Data a = String - (a - b) - Maybe b -- Oscar 2010/5/16 José Pedro Magalhães j...@cs.uu.nl Hi Oscar, On Sat, May 15, 2010 at 22:19, Oscar Finnsson oscar.finns...@gmail.com wrote: (...) I guess my questions are: 1. Is it possible to combine GADTs with Scrap your Boilerplate? Your GADT encodes an existential datatype. The closest attempt to encode existential types in (something like) SYB that I know of is in Section 5.3 of Alexey's PhD thesis [1]. Having said that, he uses the spine view, which makes the generic view in SYB explicit, but this has never been packaged as a library. So I'm afraid the answer is no. The link above might still be useful for your understanding of why this is a complex problem, though. Cheers, Pedro [1] http://igitur-archive.library.uu.nl/dissertations/2009-0518-200422/UUindex.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe