Re: [Haskell-cafe] Haskell syntax highlighting in a public blog
Another alternative is to use the HsColour package: http://code.haskell.org/~malcolm/hscolour/ and choose html as output. (This works for me on blogspot.com) On 9 August 2011 05:16, Daniel Patterson wrote: > > On Aug 8, 2011, at 10:26 PM, Ivan Lazar Miljenovic wrote: > > On 9 August 2011 12:04, Arlen Cuss wrote: > > 9/08/2011 11:54 AM, Oscar Picasso kirjutas: > > Hi, > > > Is there a public blog that that allow syntax highlighting of Haskell code? > > > Are you talking about a plugin for a blog engine? CodeColourer on > > WordPress will do it. > > > I think he meant more along the lines of wordpress.com, which as far > as I know _doesn't_ support highlighting Haskell. > > > I haven't done this personally, but here is a javascript based solution > that should work with any blog that allows you to include custom stylesheets > / javascript: > http://nix-tips.blogspot.com/2010/09/javascript-highlighter-for-haskell-code.html > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- http://adoseoflogic.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Cabal update problem
I had the same problem on Windows XP when doing cabal install cabal-install. I fixed it by just replacing the cabal-install executable by the old one used in the haskell platform. Cheers, Bas On 19 February 2010 16:11, Maciej Podgurski wrote: > Am 19.02.2010 15:29 schrieb Christian Maeder: > > Sorry, I've got no further idea (except reinstalling everything). >> >> http://hackage.haskell.org/trac/hackage/ticket/562 >> may be related. >> >> Did your installation of cabal-install-0.8.0 also reinstall HTTP and >> zlib packages? >> >> > > Yes, I installed the latest versions of that packages. Now I tried to > gradually go back to the versions before (HTTP-4000.0.9 to 4000.0.7 and > zlib-0.5.2.0 to 0.5.0.0), without any success. Finally cabal-install made it > at version 0.6.2, so the problem really seems to be at cabal-install-0.8.0. > > > Good luck >> Christian >> >> Maciej Podgurski schrieb: >> >> >>> Am 19.02.2010 12:57 schrieb Christian Maeder: >>> >>> Maciej Podgurski schrieb: > Hi, > > after updating to cabal-install-0.8.0/Cabal-1.8.0.2 with GHC 6.10.4, I > always get an error when updating the package list: > > > cabal update > Downloading the latest package list from hackage.haskell.org > cabal: Codec.Compression.Zlib: premature end of compressed stream > > Is there a way to fix this without rebuilding from the latest darcs > repo? > > Does removing ~/.cabal/packages/hackage.haskell.org/00-index.tar.gz help? Did you overwrite your old cabal-binary. If not, does this binary also fail? >>> Removing this file doesn't help. The old version was cabal-install-0.6.2 >>> + Cabal-1.6.0.2 with GHC 6.10.3. I deleted it because I changed to GHC >>> 6.10.4, but it worked fine 2 days ago. >>> >>> >>> (I think everything under ~/.cabal/packages/hackage.haskell.org can be savely deleted and will be downloaded again if needed.) Which architecture you're on? >>> Windows XP >>> >>> >>> Best wishes, >>> >>> Maciej >>> >>> >>> Cheers Christian > Best wishes, > > Maciej > > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-caf >>> ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- http://adoseoflogic.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] river crossing puzzle
Or you could look at my blog posts describing the implementation of the Cannibals and Missionaries variant step by step. First a naive approach and secondly using a state monad solution. http://adoseoflogic.blogspot.com/2009/07/cannibals-missionaries-and-state-monad.html Cheers, Bas 2009/9/28 pat browne > Hi, > Does anyone know where there are any Haskell implementations of the the > River Crossing puzzle (AKA Farmer/Fox/Goose/Grain). > There are several variations but the general ideas are explained at: > http://en.wikipedia.org/wiki/River_crossing_puzzle > http://en.wikipedia.org/wiki/Fox,_goose_and_bag_of_beans_puzzle > > I have found one at: > http://www.shido.info/hs/haskell9.html > > > Thanks, > Pat > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- http://adoseoflogic.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Haskell Cafe] Parsec: buildExpressionParser and parens typecheck problem
Hello Paul, As far as I can see you're calling the parens accessor function of the TokenParser record instead of supplying a parser. Here is a working example grammar I made for my bachelor paper a while ago: module ExpressionsWithLexer where import Text.ParserCombinators.Parsec.Expr import Text.ParserCombinators.Parsec import qualified Text.ParserCombinators.Parsec.Token as P import Text.ParserCombinators.Parsec.Language {- Leftassociative: +, -, *, / Rightassociative: ^ Priority 1: +,- Priority 2: *, / Priority 3: ^ expr ::= factor (op factor)* factor ::= number | '(' expr ')' op ::= '+' | '-' | '*' | '/' | '^' number ::= ('0' | '1' | ... | '9')+ -} lexer :: P.TokenParser () lexer = P.makeTokenParser (emptyDef { reservedOpNames = ["*","/","+","-", "^"] }) whiteSpace= P.whiteSpace lexer natural = P.natural lexer parens = P.parens lexer reservedOp = P.reservedOp lexer gram = do whiteSpace x <- expr eof return x expr :: Parser Integer expr = buildExpressionParser table factor "expression" -- Earlier in the list means a higher priority table = [[op "^" (^) AssocRight] ,[op "*" (*) AssocLeft, op "/" div AssocLeft] ,[op "+" (+) AssocLeft, op "-" (-) AssocLeft] ] where op s f assoc = Infix (do{ reservedOp s; return f} "operator") assoc factor = natural <|> (parens expr "factor") run :: Show a => Parser a -> String -> IO () run p input = case (parse p "" input) of Left err -> do{ putStr "parse error at " ; print err } Right x -> print x exampleRun = run gram "(10 ^3 - (1 + 3))" This grammar parses the EBNF like grammar included in the source. As you can see parens is an accessor function of the TokenParser record. A TokenParser record is thus produced by calling makeTokenParser and supplying that function with a language definition. I used the emptyDef (empty definition) as an argument for the makeTokenParser and only updated the operatornames. After constructing a TokenParser parsers such as parens are accessed by their accessor functions. For ease of use you can use a qualified import for the token parser module and define the parens parser and other parsers at toplevel like I did. I only tested this with Parsec 2.1.0.1 but the idea should be the same. You can read some more explanations and examples in my bachelor paper if you'd like[1][2]. Good luck, Bas van Gijzel (server is currently down :( ) [1] Comparing Parser Construction Techniques: http://referaat.cs.utwente.nl/new/papers.php?confid=12 [2] Parser Code: http://fmt.cs.utwente.nl/~michaelw/projects/vgijzel/ParserCode.zip<http://fmt.cs.utwente.nl/%7Emichaelw/projects/vgijzel/ParserCode.zip> On Sat, Jul 11, 2009 at 00:27, Paul Sujkov wrote: > Hi haskellers, > > I'm trying to use buildExpressionParser parser generator from ParsecExpr > module of Parsec ( > http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#ParsecExpr). It > works well, except for the "parens" token parser ( > http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#parens). This code > (sample from Expressions part of the manual) typechecks fine: > > expr:: Parser Integer > expr= buildExpressionParser table factor > "expression" > > table = [[op "*" (*) AssocLeft, op "/" div AssocLeft] > ,[op "+" (+) AssocLeft, op "-" (-) AssocLeft] > ] > where > op s f assoc > = Infix (do{ string s; return f}) assoc > > > factor = do{ char '(' > ; x <- expr > ; char ')' > ; return x > } > <|> number > "simple expression" > > but if I try to use parens: > > factor = parens expr > <|> number > "simple expression" > > it fails to typecheck: > > Couldn't match expected type `GenTokenParser s u m' >against inferred type `Parser Integer' > In the first argument of `parens', namely `expr' > In the first argument of `(<|>)', namely `parens expr' > In the first argument of `()', namely `parens expr <|> number' > Failed, modules loaded: none. > > the type of expr infers to GenParser Char () Integer, and the expected type > for the parens is GenTokenParser s u m (however, manual introduces it
Re: [Haskell-cafe] Just 3 >>= (1+)?
Hey Michael, If you would look at the type of >>=, it would give (>>=) :: (Monad m) => m a -> (a -> m b) -> m b and specifically in your case: (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b You are applying Just 3 as first argument, which is correct, but then supply a partially applied function (1+) which is of type Num a => a -> a, while it should be a -> Maybe b. What are you expecting as result? You cannot pull something out of a monad using a bind operator. Maybe you meant something like this? (Just 3) >>= \x -> return (x + 1) Notice how Just 3 is just the Maybe a argument, and \x -> return (x + 1) is the (a -> Maybe b) argument, finally delivering a Just 4 (of type Maybe b). (This is the same as do x <- Just 3 return (x + 1) ) Oh and btw, fail should take an argument (the error string). Good luck, Bas van Gijzel On Sat, May 9, 2009 at 9:31 PM, michael rice wrote: > Why doesn't this work? > > Michael > > > > data Maybe a = Nothing | Just a > > instance Monad Maybe where > return = Just > fail = Nothing > Nothing >>= f = Nothing > (Just x) >>= f = f x > > instance MonadPlus Maybe where > mzero = Nothing > Nothing `mplus` x = x > x `mplus` _ = x > > > > [mich...@localhost ~]$ ghci > GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help > Loading package ghc-prim ... linking ... done. > Loading package integer ... linking ... done. > Loading package base ... linking ... done. > Prelude> Just 3 >>= (1+) > > :1:0: > No instance for (Num (Maybe b)) > arising from a use of `it' at :1:0-14 > Possible fix: add an instance declaration for (Num (Maybe b)) > In the first argument of `print', namely `it' > In a stmt of a 'do' expression: print it > Prelude> > > > > ___ > 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 implementing an off-side rule in Parsec 2
Hey, Thanks for the help thusfar. These are interesting suggestions, and I think the occam-pi compiler would help a bit as example. I'll force myself to learn some more about the state monad, but I haven't found really good examples except in Real World Haskell until now so I hope I'll manage. I'll keep you posted about my further progress. Cheers, Bas On Tue, Apr 28, 2009 at 2:04 PM, Neil Brown wrote: > Bas van Gijzel wrote: > >> Hello everyone, >> >> I'm doing a bachelor project focused on comparing parsers. One of the >> parser libraries I'm using is Parsec (2) and I'm going to implement a very >> small subset of haskell with it, with as most important feature the off-side >> rule (indentation based parsing) used in function definitions and possibly >> in where clauses. >> >> But I'm still a bit stuck on how to implement this cleanly. I tried to >> search for some examples on blogs but I haven't found anything yet. As far >> as I can see the way to go would be using getState and updateState methods >> defined in Parsec.Prim and to use the methods in Parsec.Pos to compare the >> difference in indendation for tokens. >> >> But I haven't completely wrapped my head around any state monad yet and I >> don't understand Parsec enough yet to see how to use the methods Parsec.Pos >> and state easily. Some examples or pointers to something to read would >> really be helpful. >> > Hi, > > I work on a compiler for occam-pi, which has indentation-based syntax. > It's regular (two-spaces per indent) rather than > different-number-of-spaces, and line continuations can only follow certain > tokens, but perhaps our code might help you. > > We use alex for tokenising and parsec for parsing. We tokenise the file, > and then use the source positions to create indent/outdent tokens in the > token stream, and after that the parser parses things like a PAR block as: > do {reserved "PAR"; indent; many1 subItem; outdent}. Our code can be found > at: > > http://offog.org/darcs/tock/ > > Look in the frontends subdirectory, particularly at StructureOccam.hs, but > also LexOccam.x and ParseOccam.hs. It may not be the most elegant way to do > things (occam has all sorts of oddities that make parsing a pain), but it > does work :-) > > Thanks, > > Neil. > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Question about implementing an off-side rule in Parsec 2
Hello everyone, I'm doing a bachelor project focused on comparing parsers. One of the parser libraries I'm using is Parsec (2) and I'm going to implement a very small subset of haskell with it, with as most important feature the off-side rule (indentation based parsing) used in function definitions and possibly in where clauses. But I'm still a bit stuck on how to implement this cleanly. I tried to search for some examples on blogs but I haven't found anything yet. As far as I can see the way to go would be using getState and updateState methods defined in Parsec.Prim and to use the methods in Parsec.Pos to compare the difference in indendation for tokens. But I haven't completely wrapped my head around any state monad yet and I don't understand Parsec enough yet to see how to use the methods Parsec.Pos and state easily. Some examples or pointers to something to read would really be helpful. Thanks in advance, Bas van Gijzel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe