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: Installing Idris for Linux Dummies: "The following packages are likely to be broken..." (Manny Romero) 2. Re: Is it possible to "run" JSON Parser? (Baa) 3. Path {Abs|Rel} {Dir|File} type question (Baa) 4. Re: Path {Abs|Rel} {Dir|File} type question (Yitzchak Gale) 5. Re: Path {Abs|Rel} {Dir|File} type question (Baa) ---------------------------------------------------------------------- Message: 1 Date: Tue, 29 Aug 2017 23:52:14 +0200 From: "Manny Romero" <mannyrom...@mail.com> To: "David McBride" <toa...@gmail.com> Cc: Haskell Beginners <beginners@haskell.org> Subject: Re: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." Message-ID: <trinity-3c0cd249-d360-4734-9a83-d1ef2d0f1f71-1504043534543@3c-app-mailcom-lxa10> Content-Type: text/plain; charset="utf-8" An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170829/51f7579a/attachment-0001.html> ------------------------------ Message: 2 Date: Wed, 30 Aug 2017 09:53:55 +0300 From: Baa <aqua...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Is it possible to "run" JSON Parser? Message-ID: <20170830095355.1e9a0076@Pavel> Content-Type: text/plain; charset=US-ASCII Thank you, David. 1st way seems to be most close to my task. But from your answers I see that actually no way to "run" Aeson Parser monad except with ByteString argument (even not a direct "run"), right? I check Aeson sources and IMHO no exporting functions to do it... Anyway, thank you again! > There are three ways to go about this. > > Method one, we could turn all the Values into Maybe MyTypes. > Method two, we could filter out any Value which cannot be turned into > an MyType. Method three, we could fail to parse entirely if any Value > cannot be turned into a MyType succesfully. > > Here is some code that demonstrates all three approaches. > > import Data.Aeson > import Data.Aeson.Types (Parser) > import Control.Monad > import qualified Data.Text as T > import Data.Maybe (catMaybes) > > data Resp = Resp { > rHeadings :: [T.Text], > rows1 :: [Maybe MyType], > rows2 :: [MyType], > rows3 :: [MyType] > } > > data MyType = MyType > > instance FromJSON Resp where > parseJSON = withObject "Resp" $ \v -> do > hds <- v .: "headings" > > > -- we could catch all of mytypes as maybes > r1 <- fmap f <$> v .: "rows" :: Parser [Maybe MyType] > > -- we could throw away values which can't be turned into MyType > r2 <- catMaybes . fmap f <$> v .: "rows" :: Parser [MyType] > > -- we could fail the parse entirely if any value fails. > r3 <- v .: "rows" >>= traverse f' > pure $ Resp hds r1 r2 r3 > > f :: Value -> Maybe MyType > f v = undefined > > f' :: Value -> Parser MyType > f' (String t) = pure MyType > f' (Bool t) = pure MyType > f' (Number t) = pure MyType > f' (Null) = pure MyType > -- Anything that is not one of the above will cause a failure of the > entire parse. > f' _ = mzero > > On Tue, Aug 29, 2017 at 11:58 AM, Baa <aqua...@gmail.com> wrote: > > Hello List again! :) > > > > If I have a `FromJSON` instance, with `parseJSON` which translates > > `Value` to MyType, how can I run this parser like I "run" > > state/writer/reader monads? I mean not decoding of a bytestring > > representation: > > > > decode::ByteString -> Maybe MyType > > > > but > > > > run::Value -> Maybe MyType > > > > The reason is that I have already collected Value's , and I have > > parsers, so what is the problem, it would seem, to run parser on the > > Value - to convert `Value` into `Maybe MyType`... Is it possible? > > > > === > > Best regards, Paul > > _______________________________________________ > > Beginners mailing list > > Beginners@haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 3 Date: Wed, 30 Aug 2017 10:30:45 +0300 From: Baa <aqua...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Path {Abs|Rel} {Dir|File} type question Message-ID: <20170830103045.528468d0@Pavel> Content-Type: text/plain; charset=US-ASCII Hello, List! There is a library https://hackage.haskell.org/package/path-0.6.1 of Chris Done from FPCOMPLETE. `Path` - to be safe - can be constructed only with parsing (with TH or directly). OK. But the `Path` has different representation on Windows and POSIX which seems that no way to use both on the same platform (source of path can be network peer which has another platform). Does anyone use this library and if does - how do you workaround this? === Best regards, Paul ------------------------------ Message: 4 Date: Wed, 30 Aug 2017 13:27:55 +0300 From: Yitzchak Gale <g...@sefer.org> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Path {Abs|Rel} {Dir|File} type question Message-ID: <caorualzhbayk5jsqtzzbqddmjtawmxenecexsq7cjuwrx0r...@mail.gmail.com> Content-Type: text/plain; charset="UTF-8" Hi Paul, You wrote: > [In the path library] the `Path` has different representation > on Windows and POSIX which seems that no way > to use both on the same platform You are right, the path library does not yet support that. This issue will fix it: https://github.com/commercialhaskell/path/issues/82 In the meantime, use the standard filepath library, which supports paths from other platforms. Regards, Yitz ------------------------------ Message: 5 Date: Wed, 30 Aug 2017 13:46:54 +0300 From: Baa <aqua...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Path {Abs|Rel} {Dir|File} type question Message-ID: <20170830134654.5f773747@Pavel> Content-Type: text/plain; charset=US-ASCII Hmm, OK. Thank you, Yitzchak! IMHO it will be good to have like in Python: all kind of paths (NT, POSIX, etc) available as well as local path (local platform dependent)... > Hi Paul, > > You wrote: > > [In the path library] the `Path` has different representation > > on Windows and POSIX which seems that no way > > to use both on the same platform > > You are right, the path library does not yet support that. > This issue will fix it: > > https://github.com/commercialhaskell/path/issues/82 > > In the meantime, use the standard filepath library, which > supports paths from other platforms. > > Regards, > Yitz > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 110, Issue 26 ******************************************