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. How to parse JSON into existential type (Baa) 2. Re: How to parse JSON into existential type (David McBride) 3. Installing Idris for Linux Dummies: "The following packages are likely to be broken..." (Manny Romero) 4. Re: Installing Idris for Linux Dummies: "The following packages are likely to be broken..." (David McBride) 5. Re: How to parse JSON into existential type (Baa) 6. Re: Multiline code in GHCi (Shishir Srivastava) ---------------------------------------------------------------------- Message: 1 Date: Tue, 29 Aug 2017 15:36:05 +0300 From: Baa <aqua...@gmail.com> To: "beginners@haskell.org" <beginners@haskell.org> Subject: [Haskell-beginners] How to parse JSON into existential type Message-ID: <20170829153605.4a8cbd01@Pavel> Content-Type: text/plain; charset=US-ASCII Hello List! In some of my JSONs I have part "list of any values", for example: [1, "hi", "false", 2.71] To parse it I create type like: data RespItem = forall a. FromJSON a => RespItem { riItem :: [a] } ,------------------------------------------------------------------- | btw, I try `(FromJSON a, Show a, Generic a) => ...` also but don't | see any difference, so I'm not sure what is right constraints list. `------------------------------------------------------------------- And GHC does not allow to derive automatically with "deriving" Show and Generic instances for existential types, as I see. So I write: instance Generic RespItem instance Show RespItem Also this type `RespItem` in part of another one: data Resp = Resp { rHeadings :: [T.Text] , rRow :: [RespItem] } deriving (Generic, Show) Interesting is that now auto-`deriving` works! OK, but I need to to instantiate `FromJSON` for RespItem because next step must be `FromJSON` for Resp. So I'm trying: instance FromJSON RespItem where parseJSON ??? = ??? and here I get different errors, and absolutely don't understand how to parse it, I get "ambiguous type error..." and so on (which is right, sure). === Best regards, Paul ------------------------------ Message: 2 Date: Tue, 29 Aug 2017 08:56:06 -0400 From: David McBride <toa...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] How to parse JSON into existential type Message-ID: <can+tr425fxwpohdrx2mpwim57loa73mcah5conmcqvje6zd...@mail.gmail.com> Content-Type: text/plain; charset="UTF-8" Rather than having an existential, which is difficult to work with at the best of times, how about making RespItem into something concrete? You could make your own data type to represent strings and arrays and objects, etc, but you could also just use Value from aeson, since it already exists and already has a FromJSON instance. data Resp = Resp { rHeadings :: [T.Text], rRow :: [Data.Aeson.Value] } I couldn't get deriving Generic to work, but I've personally not had too much trouble writing aeson instances manually. instance FromJSON Resp where parseJSON = withObject "Resp" $ \v -> Resp <$> v .: "headings" <*> v .: "rows" There is also an aeson-lens package that can make parsing json easy, if you are into lenses. On Tue, Aug 29, 2017 at 8:36 AM, Baa <aqua...@gmail.com> wrote: > Hello List! > > In some of my JSONs I have part "list of any values", for example: > > [1, "hi", "false", 2.71] > > To parse it I create type like: > > data RespItem = forall a. FromJSON a => RespItem { > riItem :: [a] } > > ,------------------------------------------------------------------- > | btw, I try `(FromJSON a, Show a, Generic a) => ...` also but don't > | see any difference, so I'm not sure what is right constraints list. > `------------------------------------------------------------------- > > And GHC does not allow to derive automatically with "deriving" Show > and Generic instances for existential types, as I see. So I write: > > instance Generic RespItem > instance Show RespItem > > Also this type `RespItem` in part of another one: > > data Resp = Resp { > rHeadings :: [T.Text] > , rRow :: [RespItem] > } deriving (Generic, Show) > > Interesting is that now auto-`deriving` works! OK, but I need to > to instantiate `FromJSON` for RespItem because next step must be > `FromJSON` for Resp. So I'm trying: > > instance FromJSON RespItem where > parseJSON ??? = ??? > > and here I get different errors, and absolutely don't understand how to > parse it, I get "ambiguous type error..." and so on (which is right, > sure). > > > === > Best regards, Paul > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 3 Date: Tue, 29 Aug 2017 15:02:31 +0200 From: "Manny Romero" <mannyrom...@mail.com> To: beginners@haskell.org Subject: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." Message-ID: <trinity-c35811c3-763a-4a20-99a4-59e766e6f319-1504011750999@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/a45a58f2/attachment-0001.html> ------------------------------ Message: 4 Date: Tue, 29 Aug 2017 09:08:35 -0400 From: David McBride <toa...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Installing Idris for Linux Dummies: "The following packages are likely to be broken..." Message-ID: <can+tr41q_g1wpugxpzpjgxnkfp8qc6z1mkyzuurwtx3pu6c...@mail.gmail.com> Content-Type: text/plain; charset="UTF-8" The problem most users face with using straight up cabal is that often the needs of one package conflict with the needs of some of the others you've installed. I highly recommend you use stack to install idris. The process should look something like this: download stack, install it. (directions here: https://docs.haskellstack.org/en/stable/README/) git clone https://github.com/idris-lang/Idris-dev.git cd idris-dev stack install And then either run ~/.local/bin/idris or make sure .local/bin is in your PATH so that you can run idris on the command line. On Tue, Aug 29, 2017 at 9:02 AM, Manny Romero <mannyrom...@mail.com> wrote: > I am a Linux user (Mint 18) trying to install Idris. I don't know the > slightest thing about computers. I barely managed to install Linux, and > later the full GHC, based on ample instructions available on the Web. (Still > don't actually recall how I did it!) > > Idris, however, seems a little trickier. I followed the website > (https://www.idris-lang.org/download/)'s instructions: > > cabal update > cabal install idris > > ...because apparently I installed "cabal" at some point. But I get this > message, which apparently is quite common: > > cabal: The following packages are likely to be broken by the reinstalls: > semigroupoids-5.1 > lens-4.15.1 > kan-extensions-5.0.1 > profunctors-5.2 > comonad-5 > bifunctors-5.4.1 > Use --force-reinstalls if you want to install anyway. > > ...those are some of my favorite things! I can't live without them! I am > reading things about creating a "sandbox" and so forth. But I cannot use or > make sense of this information. I don't know the first thing about cabal; I > never use it; I just load everything into GHCI all the time. > > Does anyone have some *specific* instructions that I can follow (as "rotely" > and dumbly as possible) to get Idris downloaded so I can use it for some > beginning studies, without breaking Haskell? > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > ------------------------------ Message: 5 Date: Tue, 29 Aug 2017 16:08:51 +0300 From: Baa <aqua...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] How to parse JSON into existential type Message-ID: <20170829160851.2e15c95b@Pavel> Content-Type: text/plain; charset=US-ASCII Ohh, right, there is `Value`!! Thank you David for good idea! > Rather than having an existential, which is difficult to work with at > the best of times, how about making RespItem into something concrete? > You could make your own data type to represent strings and arrays and > objects, etc, but you could also just use Value from aeson, since it > already exists and already has a FromJSON instance. > > data Resp = Resp { > rHeadings :: [T.Text], > rRow :: [Data.Aeson.Value] > } > > I couldn't get deriving Generic to work, but I've personally not had > too much trouble writing aeson instances manually. > > instance FromJSON Resp where > parseJSON = withObject "Resp" $ \v -> Resp <$> v .: "headings" <*> > v .: "rows" > > There is also an aeson-lens package that can make parsing json easy, > if you are into lenses. > > > On Tue, Aug 29, 2017 at 8:36 AM, Baa <aqua...@gmail.com> wrote: > > Hello List! > > > > In some of my JSONs I have part "list of any values", for example: > > > > [1, "hi", "false", 2.71] > > > > To parse it I create type like: > > > > data RespItem = forall a. FromJSON a => RespItem { > > riItem :: [a] } > > > > ,------------------------------------------------------------------- > > | btw, I try `(FromJSON a, Show a, Generic a) => ...` also but don't > > | see any difference, so I'm not sure what is right constraints > > list. > > `------------------------------------------------------------------- > > > > And GHC does not allow to derive automatically with "deriving" Show > > and Generic instances for existential types, as I see. So I write: > > > > instance Generic RespItem > > instance Show RespItem > > > > Also this type `RespItem` in part of another one: > > > > data Resp = Resp { > > rHeadings :: [T.Text] > > , rRow :: [RespItem] > > } deriving (Generic, Show) > > > > Interesting is that now auto-`deriving` works! OK, but I need to > > to instantiate `FromJSON` for RespItem because next step must be > > `FromJSON` for Resp. So I'm trying: > > > > instance FromJSON RespItem where > > parseJSON ??? = ??? > > > > and here I get different errors, and absolutely don't understand > > how to parse it, I get "ambiguous type error..." and so on (which > > is right, sure). > > > > > > === > > 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: 6 Date: Tue, 29 Aug 2017 16:04:53 +0100 From: Shishir Srivastava <shishir.srivast...@gmail.com> To: beginners <beginners@haskell.org> Subject: Re: [Haskell-beginners] Multiline code in GHCi Message-ID: <CALe5RTtqKtkcpozs_rzcxU4wbkOoYk=jxtzvp8isrvk8dtx...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Just revisiting haskell after a hiatus and to begin that with a rather uncalled for query - In the system type declaration for the data type Bool as below what are the types of the two values 'True' and 'False' *data Bool = False | True* Are the values 'String' ? In which case how's the Bool data type different from String enumerator data type ? Thanks, S -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170829/6449be24/attachment.html> ------------------------------ 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 23 ******************************************