Re: [Haskell-cafe] ghc-api Static Semantics?
Hi Thomas, By static semantics I mean use and bind locations for every name in the AST. For example: f x = let x = x + 1 in x Should parse as something like HsMatch (f (HsPat x (1,2) (1,2)) (HsBody (HsExp (HsLet (HsMatch (x (8,1) (8,1)) (HsExp (HsInfix (+) (1) (x) (12,1) (8,1)) (x (16,1) (8,1 I'm steering towards haskell-src-exts right now as the sheer complexity of the ghc-api is putting me off. I need something simple, as I can't be spending all my time learning the ghc-api and hacking it together to do what I want. It does look a bit of a mess. Just trying to do simple things like parsing a file and showing its output proved to be much more complicated than it really needed to be. Let me know if you decide to take on this project. We have decided to take it on. :) Chris. On 24 January 2012 10:35, Christopher Brown cm...@st-andrews.ac.uk wrote: Have you looked at ghc-syb-utils, which gives a neat way to print an AST? http://hackage.haskell.org/packages/archive/ghc-syb-utils/0.2.1.0/doc/html/GHC-SYB-Utils.html Yes I found that yesterday! Chris. -- JP Moresmau http://jpmoresmau.blogspot.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 -- Push the envelope. Watch it bend. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghc-api Static Semantics?
Hi Ozgur, Yes I've looked at haskell-src-exts and it does look *much* easier to use. I need this to build a new refactoring tool for Haskell (for the Paraphrase project). One advantage to using the ghc-api directly is that's it's always cutting edge and maintained by the ghc team. Having one more library dependancy to worry about is not always a good thing. At the moment (and spending half a day yesterday just working out how to 'show' an AST from the ghc-api) I'm veering towards haskell-src-exts. I think extending it to contain use and bind locations in the AST would be the best option for me. There's also a question of having types in the AST as well. I don't know what you actually need, but if haskell-src-exts is an option, it is quite a bit easier to use (definitely easier to understand for me!). Especially when used together with Uniplate. For example, for a given piece of AST one can get all the identifiers used like so: [ x | Ident x - universeBi ast ] Uniplate isn't a powerful enough generic system to design a full refactoring engine, as we need top down/bottom up/ full/stop/once plus preservation and unification, much in the style of Strafunski. I think SYB is better for our needs. Perhaps we could use a combination of uniplate+SYB depending on what traversals/rewrites we need to do. Finding where they are bound shouldn't be very hard either. No, but it would be much easier if the information was already there, of course! :) Thanks for your response! Chris. Hope this helps, Ozgur On 23 January 2012 17:33, Christopher Brown cm...@st-andrews.ac.uk wrote: Hi, I was wondering if anyone could tell me if it's possible to get an AST from the ghc-api decorated with static-semantics? In particular, I am interested in use and bind locations for all names in the AST together with the module they are bound, etc. Looking through the online docs, there doesn't seem to be a way to do this. Even if I can tell from the AST where a variable is bound that would be enough, if this is by making all names unique and qualified that would be better than nothing. Hope someone can help, Chris. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] C++ Parser?
Hi, I have stumbled across language-c on hackage and I was wondering if anyone is aware if there exists a full C++ parser written in Haskell? Many thanks, Chris. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghc-api Static Semantics?
Have you looked at ghc-syb-utils, which gives a neat way to print an AST? http://hackage.haskell.org/packages/archive/ghc-syb-utils/0.2.1.0/doc/html/GHC-SYB-Utils.html Yes I found that yesterday! Chris. -- JP Moresmau http://jpmoresmau.blogspot.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] C++ Parser?
Hi Everyone, Thanks for everyone's kind responses: very helpful so far! I fully appreciate and understand how difficult writing a C++ parser is. However I may need one for our new Paraphrase project, where I may be targeting C++ for writing a refactoring tool. Obviously I don't want to start writing one myself, hence I was asking if anyone new about an already existing implementation. Rose looks interesting, I'll check that out, thanks! Chris. On 24 Jan 2012, at 14:40, Jason Dagit wrote: On Tue, Jan 24, 2012 at 2:06 AM, Christopher Brown cm...@st-andrews.ac.uk wrote: Hi, I have stumbled across language-c on hackage and I was wondering if anyone is aware if there exists a full C++ parser written in Haskell? I don't think one exists. I've heard it's quite difficult to get template parsing working in an efficient manner. My understanding is that real C++ compilers use the Edison Design Group's parser: http://www.edg.com/index.php?location=c_frontend For example, the Intel C++ compiler uses the edg front-end: http://en.wikipedia.org/wiki/Intel_C%2B%2B_Compiler I thought even microsoft's compiler (which is surprisingly c++ compliant) uses it but I can't find details on google about that. There is at least one open source project using it, rose, so it's not unthinkingable to use it from Haskell: http://rosecompiler.org/ Rose has had working haskell bindings in the past but they have bit rotted a bit. With rose you get support for much more than parsing C++. You also get C and Fortran parsers as well as a fair bit of static analysis. The downside is that rose is a big pile of C++ itself and is hard to compile on some platforms. If you made a BSD3 licensed, fully functional, efficient C++ parser that would be great. If you made it so that it preserves comments and the input well enough to do source to source transformations (unparsing) that would be very useful. I often wish I had rose implemented in Haskell instead of C++. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] C++ Parser?
Hi Jason, Thanks very much for you thoughtful response. I am intrigued about the Happy route: as I have never really used Happy before, am I right in thinking I could take the .gr grammar, feed it into Happy to generate a parser, or a template for a parser, and then go from there? Chris. On 24 Jan 2012, at 15:16, Jason Dagit wrote: On Tue, Jan 24, 2012 at 6:54 AM, Christopher Brown cm...@st-andrews.ac.uk wrote: Hi Everyone, Thanks for everyone's kind responses: very helpful so far! I fully appreciate and understand how difficult writing a C++ parser is. However I may need one for our new Paraphrase project, where I may be targeting C++ for writing a refactoring tool. Obviously I don't want to start writing one myself, hence I was asking if anyone new about an already existing implementation. Rose looks interesting, I'll check that out, thanks! I did some more digging after sending my email. I didn't learn about GLR parser when I was in school, but that seems to be what the cool compilers use these days. Then I discovered that Happy supports GLR, that is happy! Next I found that GLR supposedly makes C++ parsing much easier than LALR, The reason I wrote Elkhound is to be able to write a C++ parser. The parser is called Elsa, and is included in the distribution below. The elsa documentation should give you a flavor for what needs to be done when making sense of C++: http://scottmcpeak.com/elkhound/sources/elsa/index.html NB: I don't think it's been seriously worked on since 2005 so I assume it doesn't match the latest C++ spec. The grammar that elsa parses is here, one warning is that it doesn't reject all invalid programs (eg., it errs on the side of accepting too much): http://scottmcpeak.com/elkhound/sources/elsa/cc.gr I think the path of least resistance is pure rose without the haskell support. Having said that, I think the most fun direction would be converting the elsa grammar to happy. It's just that you'll have a lot of work (read: testing, debugging, performance tuning, and then adding vendor features) to do. One side benefit is that you'll know much more about the intricacies of C++ when you're done than if you use someone else's parser. Jason ___ 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] ghc-api Static Semantics?
Hi, I was wondering if anyone could tell me if it's possible to get an AST from the ghc-api decorated with static-semantics? In particular, I am interested in use and bind locations for all names in the AST together with the module they are bound, etc. Looking through the online docs, there doesn't seem to be a way to do this. Even if I can tell from the AST where a variable is bound that would be enough, if this is by making all names unique and qualified that would be better than nothing. Hope someone can help, Chris. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Editors for Haskell
Hi Walt, For Mac OS X I would strongly recommend using Sub Etha Edit. Its a very simple editor to use, and offers a lot of power and flexibility. It also has a Haskell highlighting mode. You can find it at: http://www.codingmonkeys.de/subethaedit/ Chris. On 25 May 2006, at 16:02, Walter Potter wrote: All, I hope that this is the right place for this question. I'm using Haskell (GHC and Hugs) on several different platforms. Windows, OS X and Linux systems. I'd like to have an IDE that works well for medium to large size projects. I know of Eclipse and hIDE. Vim works fine but I'd like more. hiDE seems to be in process. What would you suggest? I'll be asking my students to use the same IDE. Thanks, Walt ___ 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] Strafunski
Hi, I am trying to use Strafunski with GHC 6.5 and was wondering if someone could help me. I have all the instances for Term and Typeable defined for my data types, but when I try to compile with GHC 6.5 I get lots of overlapping instance errors. In particular, it seems the instances I am using (generated by DrIFT) are clashing with the ones in Data.Typeable. Is there a way I can fix this? Also I have heard that it is possible to add deriving Typeable to each data type and I don't need to use the instances I have created. However, now it complains that it can't find instances for Term - but I can't derive from Term. Does anyone have any ideas how I can get Strafunski working with GHC 6.5? Thanks. Chris. Christopher Brown PhD Student, University of Kent. http://www.cs.kent.ac.uk/people/rpg/cmb21/ [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Strafunski
Christian, Did you try the switch -fallow-overlapping-instances when compiling? Yes, but it doesn't seem to make much difference. Cheers, Chris. Cheers Christian Christopher Brown PhD Student, University of Kent. http://www.cs.kent.ac.uk/people/rpg/cmb21/ [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strafunski
Joost, Thanks very much - this solved my problem! Cheers Chris. On 3 Apr 2006, at 17:03, Joost Visser wrote: Hi Chris, Changes in the libraries of GHC have broken Strafunski compatibility in the past. I have not upgraded to GHC 6.5 myself so I'm not sure if this is the case again. Which versions of DrIFT and Strafunski are you using? Based on what you write, it seems new instances for Typeable have been added to the libs (possibly using deriving), which means some of your own instances are now redundant. You'll have to remove them (which will then break compatibility of your code with 6.4.1, sigh). Alternatively, you may consider to switch from the drift-default mode of Strafunski to the deriving mode. This means that you will be relying on the Typeable+Data classes rather than on the Typeable +Term classes. You make the switch simply by changing the search path, all your strategic functions should work like before. I guess GHC 6.5 supports deriving both for Typeable and Data (personally, I prefer to use DriFT rather than the deriving clause, because it gives me a bit more control over visibility of instances). For details, see the section Supported models of functional strategies in the README file of StrategyLib. Regards, Joost -- Dr. ir. Joost Visser | Departamento de Informática phone +351-253-604461 | Universidade do Minho fax+351-253-604471 | mailto:[EMAIL PROTECTED] mobile +351-91-6253618 | http://www.di.uminho.pt/~joost.visser On Apr 3, 2006, at 3:41 PM, Christopher Brown wrote: Hi, I am trying to use Strafunski with GHC 6.5 and was wondering if someone could help me. I have all the instances for Term and Typeable defined for my data types, but when I try to compile with GHC 6.5 I get lots of overlapping instance errors. In particular, it seems the instances I am using (generated by DrIFT) are clashing with the ones in Data.Typeable. Is there a way I can fix this? Also I have heard that it is possible to add deriving Typeable to each data type and I don't need to use the instances I have created. However, now it complains that it can't find instances for Term - but I can't derive from Term. Does anyone have any ideas how I can get Strafunski working with GHC 6.5? Thanks. Chris. Christopher Brown PhD Student, University of Kent. http://www.cs.kent.ac.uk/people/rpg/cmb21/ [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Christopher Brown PhD Student, University of Kent. http://www.cs.kent.ac.uk/people/rpg/cmb21/ [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] show for functional types
Here is another example. Consider two functions f and g which, given the same inputs, always return the same outputs as each other such as: f x = x + 2 g x = x + 1 + 1 Now since f and g compute the same results for the same inputs, anywhere in a program that you can use f you could just replace f by g and the observable behaviour of the program would be completely unaffected. This is what referential transparency means. Another example: In haskell the following is true: f x + g x == g x + f x Pure functions in Haskell do not have side effects, so for the same inputs they always give back the same output. This is referential transparency. In a language such as C, which does not have referential transparency, the functions f and g may change x by a side effect and therefore: f x + g x /= g x + f x In C (or a language with side effects). Cheers, Chris. Christopher Brown PhD Student, University of Kent. http://www.cs.kent.ac.uk/people/rpg/cmb21/ [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe