Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: Custom type classes (Daniel Hinojosa) 2. Re: compilation error for jhc (Fabien R) 3. Re: Parsing 'A's and then ('A's or 'B's) (Francesco Ariis) ---------------------------------------------------------------------- Message: 1 Date: Mon, 25 Jan 2016 01:08:10 -0700 From: Daniel Hinojosa <dhinoj...@evolutionnext.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Custom type classes Message-ID: <caoxuh-5fqj-ibtysrox82ffj-fk42wq2b+m2j_3kjhegcfg...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Ah. I had a suspicion it had to do with extensions. Got to study up on it. Thanks On Jan 25, 2016 12:42 AM, "Imants Cekusins" <ima...@gmail.com> wrote: > Hello Daniel, > > it works with these tweaks: > > -- begin > > {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-} > module TupInst where > > > data Tuple3 a b c = Tuple3 a b c deriving (Show) > > data Tuple2 a b = Tuple2 a b deriving (Show) > > class Indexable idx a where > first :: idx -> a > > > instance Indexable (Tuple2 a b) a where > first (Tuple2 a0 b0) = a0 > > > instance Indexable (Tuple3 a b c) a where > first (Tuple3 a0 b0 c0) = a0 > > -- end > > call it in ghci like this: > > first $ Tuple3 (1::Int) 'a' False::Int > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160125/8ca3a761/attachment-0001.html> ------------------------------ Message: 2 Date: Mon, 25 Jan 2016 09:26:56 +0100 From: Fabien R <theedge...@free.fr> To: beginners@haskell.org Subject: Re: [Haskell-beginners] compilation error for jhc Message-ID: <56a5dc50.2010...@free.fr> Content-Type: text/plain; charset=windows-1252 On 24/01/2016 14:59, David McBride wrote: > It looks like the binary package got its own instance for the version > datatype. You could probably make it build by just removing that instance > from Binary.hs. Thanks David, It worked fine. -- Fabien ------------------------------ Message: 3 Date: Mon, 25 Jan 2016 10:15:13 +0100 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Parsing 'A's and then ('A's or 'B's) Message-ID: <20160125091513.ga5...@casa.casa> Content-Type: text/plain; charset=utf-8 On Sun, Jan 24, 2016 at 10:56:31PM +0100, Simon Jakobi wrote: > > if I understood your specification correctly, there would be multiple > > ways to parse the string "AAA": > > > > - 3 'x' elements ("A", "A", "A") > > - 2 'x' elements ("AA", "A") > > - 2 'x' elements again (first one shorter) ("A", "AA") > > - 1 'x' element ("AAA") > > > > There would be even more ways because 'y', too, can represent one or more > 'A's. > > [...] > > Is this due to attoparsec not being able to "backtrack" (not sure if > this is the right term)? Is backtracking something that parsers generally > are incapable of? Ah, indeed you are right. attoparsec, parsec and friends handle failure with `try`. From Attoparsec documentation: Attempt a parse, but do not consume any input if the parse fails. One way to deal with cases like yours is for every parser to compute a "list of successes". Crude example: import Text.Parsec import Text.Parsec.String foo :: Parser [String] foo = anyChar >>= \h -> (foo <|> e) >>= \t -> return ([""] ++ map (h:) t) where e = return [""] -- ?> parseTest foo "bar" -- ["","b","ba","bar"] Then you can chain those with `try`/`choice` and compute your result(s) (I guess using the list monad to handle the mechanism could do). Ambiguous grammars are an age old problem, and some searching [1] leads me to believe there are already viable solution in Haskell. [1] http://stackoverflow.com/questions/13279087/parser-library-that-can-handle-ambiguity ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 91, Issue 31 *****************************************