tag:blogger.com,1999:blog-5336273.post8009657677922259357..comments2023-08-23T21:56:42.999+09:00Comments on A++ [Eric Torreborre's Blog]: My first ICFP contest, Part 2: parser combinators are so coolUnknownnoreply@blogger.comBlogger6125tag:blogger.com,1999:blog-5336273.post-72683586805970845202008-07-28T10:27:00.000+09:002008-07-28T10:27:00.000+09:00Daniel,I also love Haskell's syntax. It is tru...Daniel,<BR/><BR/>I also love Haskell's syntax. It is truly minimal *and* powerful.<BR/><BR/>The funny thing is that I don't like the infix notation with backquotes, which you don't need in Scala. On the other hand, in Haskell, you can write "function parameter" which you can't in Scala. <BR/><BR/>That would be very useful to allow this in some embedded Scala DSLs. But I guess this is not possible to have both notations available in a language with functions as first class objects.<BR/><BR/>Regarding the Scala implementation size, it seems that the Haskell implementation could also be shortened using Control.Applicative.*> . This is similar to ^^^ in Scala as far as I understand.<BR/><BR/>Similarly there should be a way to use type classes to get the same effect as implicits for letter parsers, but I haven't experimented with that yet.<BR/><BR/>Now that the contest is over, I need to find some other pet project to continue training in Haskell. Err, no. Actually I mostly need time!Erichttps://www.blogger.com/profile/16484514586929815703noreply@blogger.comtag:blogger.com,1999:blog-5336273.post-23838371229299826252008-07-28T06:54:00.000+09:002008-07-28T06:54:00.000+09:00This is how we did it in Haskell for the int and d...This is how we did it in Haskell for the int and double parsers:<BR/><BR/>int :: Parser Int<BR/>int = do digits <- many digit<BR/> spaces<BR/> return $ read digits<BR/><BR/>double :: Parser Double <BR/>double = do digits <- many doubleChars<BR/> spaces<BR/> return $ read digits<BR/> where doubleChars = oneOf "-.0123456789"<BR/><BR/>You can notice that the double parser is far from perfect since it will try to parse strings like "1-23.45-6." before failing on "read".Erichttps://www.blogger.com/profile/16484514586929815703noreply@blogger.comtag:blogger.com,1999:blog-5336273.post-54031554076562090282008-07-28T05:52:00.000+09:002008-07-28T05:52:00.000+09:00Thanks, Eric. But I was asking about haskell's "do...Thanks, Eric. But I was asking about haskell's "double" and "int" parsers ;-). <BR/><BR/>Apart from "integer haskell" (which is too hi-level), I could not find any standard ones.<BR/><BR/>Regards,Sanny Sanoffhttps://www.blogger.com/profile/12415228435621531481noreply@blogger.comtag:blogger.com,1999:blog-5336273.post-25990378672173546012008-07-28T04:29:00.000+09:002008-07-28T04:29:00.000+09:00Personally, I think that parser combinators are pr...Personally, I think that parser combinators are probably the smartest innovation in the entire world of functional programming. It is interesting that the Haskell syntax is quite a bit cleaner (no need for tildes), but the Scala implementation is shorter. It could just be language familiarity, but I like to think that it's more a factor of Scala's hybrid power. :-)Daniel Spiewakhttps://www.blogger.com/profile/17323566514229790079noreply@blogger.comtag:blogger.com,1999:blog-5336273.post-89556813703002406942008-07-27T23:36:00.000+09:002008-07-27T23:36:00.000+09:00You're right Sanny, I left them out but here t...You're right Sanny, I left them out but here they are:<BR/><BR/>def intNumber: Parser[Int] = wholeNumber <~ spaces ^^ (java.lang.Integer.parseInt(_.mkString)) <BR/><BR/>def doubleNumber: Parser[Double] = floatingPointNumber <~ spaces ^^ (java.lang.Double.parseDouble(_))<BR/><BR/>And the "spaces" parser too: <BR/><BR/>def spaces = rep(whiteSpace)Erichttps://www.blogger.com/profile/16484514586929815703noreply@blogger.comtag:blogger.com,1999:blog-5336273.post-74533256939866966652008-07-27T21:10:00.000+09:002008-07-27T21:10:00.000+09:00just curious about "double" and "int" parsers you ...just curious about "double" and "int" parsers you use; could you provide reference or implementation plz. <BR/><BR/>p.s. Scala implementation is shorter, what a piece of art!Sanny Sanoffhttps://www.blogger.com/profile/12415228435621531481noreply@blogger.com