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. help writing a simple api which queries for a resource and displays this info (xu xiut) 2. type T' = T a b c (Imants Cekusins) 3. Re: type T' = T a b c (Imants Cekusins) 4. Re: type T' = T a b c (Imants Cekusins) ---------------------------------------------------------------------- Message: 1 Date: Sun, 21 Aug 2016 16:05:52 -0600 From: xu xiut <xiut...@gmail.com> To: beginners@haskell.org Subject: [Haskell-beginners] help writing a simple api which queries for a resource and displays this info Message-ID: <CANVqfJEOwijry_o_n7KSF9sc1sni-RmsFU33EX=+rcoirq_...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello, I am wanting to store something in a database, then retrieve it. That is my entire ambition for the day. Technologies chosen: spock: https://github.com/agrafix/Spock rethinkdb driver: https://github.com/AtnNn/haskell-rethinkdb I chose to go with Rethinkdb, but i'm open to using Postgresql. If someone requests for /companies, I want to list all the companies in the "companies" table. ``` -- ghci λ> companies <- run h $ table "companies" :: IO [Datum] λ> companies [{"name":"tesla","id":"7781ee7e-1e43-4608-bb96-fe10cac3b53a"}] λ> firstCompany <- run h $ table "companies" ! "name" :: IO [Datum] λ> firstCompany ["tesla"] λ> :info Datum data Datum = Null | Bool Bool | String Text | Number Double | Array Database.RethinkDB.Datum.Array | Object Database.RethinkDB.Datum.Object | Time time-1.5.0.1:Data.Time.LocalTime.LocalTime.ZonedTime | Point LonLat | Line GeoLine | Polygon GeoPolygon | Binary bytestring-0.10.6.0:Data.ByteString.Internal.ByteString -- Defined in ‘Database.RethinkDB.Datum’ instance Eq Datum -- Defined in ‘Database.RethinkDB.Datum’ instance Ord Datum -- Defined in ‘Database.RethinkDB.Datum’ instance Show Datum -- Defined in ‘Database.RethinkDB.Datum’ instance Expr Datum -- Defined in ‘Database.RethinkDB.ReQL’ instance Result Datum -- Defined in ‘Database.RethinkDB.Driver’ instance ToDatum Datum -- Defined in ‘Database.RethinkDB.Datum’ instance FromDatum Datum -- Defined in ‘Database.RethinkDB.Datum’ 15:40 < lpaste> xuxu revised “investigating the Datum data type”: “investigating the Datum data type” at http://lpaste.net/179391 ``` I don't know how to display the result. >From Spock's readme, here's an example where I don't need to query the database: ``` main = runSpock 3000 $ spockT id $ do get "companies" $ text $ T.concat ["tesla", "google"] ``` How to convert that into something a little more practial where I do utilize a db? Here's what I have right now, but I'm sure it doesn't compile ``` {-# LANGUAGE OverloadedStrings #-} import Web.Spock import qualified Data.Text as T import qualified Database.RethinkDB as R import qualified Database.RethinkDB.NoClash default (Datum, ReQL, String, Int, Double) main :: IO () main = -- 1. i don't know if the following line will work let h = connect "localhost" 28015 Nothing in runSpock 3000 $ spockT id $ -- 2. list all companies do get "companies" $ text $ T.concat -- something ``` I don't exactly know how "text" works. If I'm reading https://github.com/agrafix/Spock/blob/1ee54503ad67f62af795a31772040f56f7ae08fd/Spock-core/src/Web/Spock/Core.hs#L55 correctly, spockT is using a reader monad. I don't know how it works with the Text type, but I have a suspicion I need to convert Rethink's Datum type into a Text type. I would be absolutely thrilled if anyone is able to help with this. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160821/a49cc985/attachment-0001.html> ------------------------------ Message: 2 Date: Mon, 22 Aug 2016 12:01:08 +0200 From: Imants Cekusins <ima...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] type T' = T a b c Message-ID: <CAP1qinZ=b6oOfnrp=relgov61t4wruzhwbg49m5dfy9nne4...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" *problem*: given type T with a few parameters e.g. T a b c some functions where this type is passed to, are agnostic to a, b, c i.e. accept T with any of a, b, c processT::T a b c -> () when either number of these parameters or T change (c is dropped or d is added: T a b c d), signatures of every function where T is passed to, need to be updated. *question*: is this possible to specify type synonym T' so that it may be passed to parameter (a,b,c) - agnostic functions so: processT::T' -> () ? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160822/355f0cb2/attachment-0001.html> ------------------------------ Message: 3 Date: Mon, 22 Aug 2016 12:29:14 +0200 From: Imants Cekusins <ima...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] type T' = T a b c Message-ID: <CAP1qinbgcY1X=4+ga95_f1o4cbqfl47wbyqrjyxbcrb5z31...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" just came across this: https://downloads.haskell.org/~ghc/7.0.3/docs/html/users_guide/data-type-extensions.html this seems to work: ExistentialQuantification Rank2Types type T' = forall a b. (T a b) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160822/3181e359/attachment-0001.html> ------------------------------ Message: 4 Date: Mon, 22 Aug 2016 13:32:15 +0200 From: Imants Cekusins <ima...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] type T' = T a b c Message-ID: <CAP1qina_z53Q3h2RJRJsuOMUutRJWdH3pCO5chYA=iejunf...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" T' and T a b seem to not mix well. T' can not be passed to a function expecting T a b and vice versa any suggestions? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160822/f734b652/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 98, Issue 13 *****************************************