<    June 2018     >
Su Mo Tu We Th Fr Sa  
                1  2  
 3  4  5  6  7  8  9  
10 11 12 13 14 15 16  
17 18 19 _2_0 21 22 23  
24 25 26 27 28 29 30
00:07 louispan joined
00:23 louispan joined
00:35 iAmerikan joined
00:49 andreabedini joined
00:55 dxld joined
00:58 justaguest joined
01:02 acarrico joined
01:10 cschneid joined
01:17 jsondavi1 joined
01:40 jmnk joined
01:47 andreabedini joined
01:58 conal_ joined
02:24 xpycm joined
02:32 Linter joined
02:41 AetherWind joined
02:45 progfun joined
02:49 emilypi joined
02:59 hphuoc25 joined
03:02 ToffeeYogurtPots joined
03:14 justaguest joined
03:19 bbrodriguez joined
03:37 cschneid joined
03:39 kroomey joined
03:56 <thekyriarchy> i'm trying to use `mkRegex` in a hakyll site but i get this `Not in scope: type constructor or class 'Regex'` error
03:56 <thekyriarchy> and when i try to `import Text.Regex[.Base/.TDFA/.Posix]` i get a `Could not find module` error even after `cabal install regex-compat`
03:56 hphuoc25 joined
03:59 <sclv> thekyriarchy: regex-compat only provides Text.Regex
03:59 <sclv> for any of the suffixes you need to install the appropriate package
03:59 <sclv> e.g. regex-posix or regex-tdfa
04:00 <sclv> actually, regex-compat implies regex-posix
04:00 <sclv> and base i guess
04:00 <sclv> just not tdfa
04:00 <sclv> but if you haven't declared the dep explicitly in your cabal file
04:01 <sclv> then its not necessarily exposed
04:02 Linter joined
04:09 <thekyriarchy> ah, i see. thanks so much
04:09 <thekyriarchy> and how do i choose which one is the most appropriate to use?
04:09 <thekyriarchy> i saw one blog post that recommended regex pcre or something
04:14 <sclv> thekyriarchy: depends what you want
04:14 <sclv> posix is sort of the standard straightforward one
04:14 <sclv> i tend to use tdfa because it is pure haskell and relatively efficient
04:15 <sclv> pcre is perl-compatible, which is sort of the richest and most complicated
04:15 <sclv> i find them a bit weird
04:15 <sclv> and i typically don't want all that stuff
04:18 taumuon joined
04:25 emilypi joined
04:26 hphuoc25 joined
04:38 progfun joined
04:41 mac10688 joined
04:59 bbrodriguez joined
05:01 eminhi joined
05:07 Zialus joined
05:09 eminhi joined
05:10 Folkol joined
05:14 hphuoc25 joined
05:19 slomo joined
05:43 giraffe joined
05:47 justaguest joined
05:50 Linter joined
05:54 bbrodriguez joined
06:22 hphuoc25 joined
06:26 Folkol_ joined
06:27 hamishmack joined
06:42 hphuoc25 joined
07:03 louispan joined
07:34 paraseba joined
07:48 justaguest joined
07:48 bergle joined
07:49 damncabbage joined
07:49 <bergle> Hi I've been working through a book Haskell from first principles. I am wondering, I am in the Applicative chapter look at ZipList' applicative. I got mine working
07:49 <bergle> but i am wondering how this persons implementation using repeat' in the pure works ? https://github.com/leshow/haskell-programming-book/blob/master/src/Ch17_ZipList.hs#L96
07:50 <bergle> at the moment it also appears that solution is much slower to run the quickTest using Checkers.
07:54 hphuoc25 joined
07:55 <dminuoso> bergle: It unnecessarily wastes space.
07:55 <dminuoso> bergle: You need to make use of sharing to avoid it.
07:55 <dminuoso> Oh wait, wrong thought.
07:56 zero_byte joined
07:56 <dminuoso> bergle: No right thought.
07:57 <jle`> yeah, repeat' should be worse space-wise
07:57 <dminuoso> jle`: wrong modal verb?
07:57 <jle`> than the repeat from Prelude
07:58 <jle`> dminuoso: heh, what is english
07:58 <bergle> im curious how it works, as the repeat' is in the pure definition.
07:58 <jle`> how repeat' works?
07:58 <bergle> it is not in the zipWith' which is where i thought itd have to be.
07:58 <bergle> i know how repeat' works
07:58 <bergle> i dont get how it being in pure works.
07:58 <bergle> what is it doing ?
07:58 <jle`> pure x = ZipList [x,x,x,x,x,x,x...]
07:59 <dminuoso> bergle: pure needs to be pure with respect to <*>
07:59 <jle`> > pure 3 :: ZipList Int
07:59 <lambdabot> ZipList {getZipList = [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3...
07:59 <bergle> oh hangon.
07:59 <dminuoso> bergle: Basically imagine that pure id <*> f = f
07:59 <jle`> ^ that's what it does :)
07:59 <bergle> duh that ws the clue.
07:59 <dminuoso> (which is one of the applicative laws)
07:59 <bergle> with respect to ZipList' duh
08:00 <dminuoso> Yup.
08:00 <bergle> so it ensurs that any list has its tail repeated ?
08:00 <jle`> not any list
08:00 <dminuoso> bergle: pure id <*> f = f
08:00 <dminuoso> pure f <*> pure x = pure (f x)
08:00 <jle`> it just gives an infinite list of all the same value
08:00 <dminuoso> Once you ponder about the laws a bit, there's only way this can work out
08:00 <jle`> bergle: what was your implementation?
08:01 <jle`> was `pure x` something other than ZipList [x,x,x,x.... forever]?
08:02 <jle`> pure x for zip list has to be ZipList [x,x,x,x,x,x.....]
08:02 <bergle> my zipWith equivalent, just ensured that the last element either first or second parameter to <*> repeated last value. - which im pretty sure is wrong to
08:02 <jle`> it doesn't matter exactly how you define it
08:02 <bergle> but passes the quickCheck checkers
08:02 <jle`> you can use repeat', or you can use whatever you used
08:02 <jle`> (if what you used was legal)
08:02 <jle`> repeat' is just one way to get ZipList [x,x,x,x,x,x...]
08:02 <jle`> but there are many other ways
08:02 <bergle> ok, i think im still missing something.
08:02 <dminuoso> bergle: another is `f <*> pure x` = pure ($ x) <*> f
08:03 <jle`> the only requirement is that pure x for ZipList has to be ZipList [x,x,x,x,x,x.....]
08:03 <jle`> bergle: can you post your instance?
08:03 <bergle> the solution linke there, how does the repeat' in pure affect <*> values passed to repeat them ?
08:03 <bergle> hangon
08:03 <bergle> is there a preferred pastebot ?
08:03 <dminuoso> bergle: The answer lies within the laws of applicative, and the structure you are inventing with <*>.
08:04 <bergle> applicative chatper has taken 10 times longer than all previous chapters for me so far ;) lol
08:06 <jle`> think of it like leveling up in an RPG
08:06 <jle`> each one takes longer than the last, but the payoff is always more rewarding :)
08:06 <bergle> hmm seems pastebin hilight of haskell not so great.
08:06 <bergle> https://pastebin.com/kXmvEdbZ
08:06 <bergle> oh im not giving up quite enjoying it, but its cause more than a few oh-duh! :)
08:07 <bergle> btw that solution passes tests, but i dont think its correct - because it does not stop with the shorter list.
08:07 <bergle> as id expect zip to work given played with the function earlier.
08:08 <jle`> oh yeah that's interesting
08:08 <jle`> your implementation breaks the laws but passes the tests
08:08 <bergle> lol.
08:08 <jle`> :'(
08:08 <dminuoso> bergle: pure id <*> v = v
08:09 <dminuoso> bergle: so if `pure` inserts some thing into an applicative, then it does it in a way, that if you insert `id` and use the "applicative apply" <*>, then the entire structure remains unscatched.
08:09 <jle`> i think bergle's implementation passes pure id <*> v
08:09 <jle`> the thing that it breaks is associativity
08:10 <dminuoso> associativity?
08:10 <bergle> it passes the tests in import Test.QuickCheck.Checkers
08:10 <dminuoso> jle`: I only know about identity, homomorphism, interchange and composition
08:10 thc202 joined
08:10 <jle`> using the monoidal formulation of applicative, there's left identity, right identity, and associativity
08:11 <dminuoso> wait this is gonna be cool and revealing.
08:11 <dminuoso> what is the monoidal formulation?
08:11 <dminuoso> the one with Day?
08:11 <jle`> it's the one that i discuss in one of my recent blog posts on Const
08:11 <jle`> but essentially <*> is monoidal on effects
08:11 <dminuoso> Do you have a link ready for that post?
08:11 <jle`> `pure ?? <*> x` should have all the effects of x, `x <*> pure ???` should ahve all of the effects of x, none more or less etc.
08:12 louispan joined
08:12 <jle`> https://blog.jle.im/entry/const-applicative-and-monoids.html
08:12 <jle`> but the monoidal formulation comes from the Typeclassopedia
08:12 <dminuoso> jle`: oh so `fmap f x = pure f <*> x` and `pure id <*> v = v` in a nutshell
08:12 <jle`> yeah, that's the left and right identity part of the monoid
08:12 will_ joined
08:12 Pupnik joined
08:13 <jle`> but if you think of <*> as being monoidal in effects, you should see that x *> (y *> z) should be the same as (x *> y) *> z
08:13 <jle`> but bergle's instance breaks this
08:13 <jle`> bergle's instance "fills" the rest of the list to match their lengths
08:13 <dminuoso> Refreshing to read a Haskell blog without category diagrams.
08:14 <jle`> but by associating x *> (y *> z) and (x *> y) *> z, you can swap the "filling item"
08:14 <bergle> btw i made mine fill beacuse it failed the Checkers test.
08:14 <bergle> but then realised it wont stop at shorter lol.
08:16 <jle`> this is defintiely an interesting case though
08:16 curious_corn joined
08:16 <jle`> where does that Test.QuickCheck.Checkers module come from?
08:16 grdryn joined
08:17 <dminuoso> jle`: Ah so I suppose it's actually associativity of the monoidal category with the Day bifunctor?
08:17 <dminuoso> (internally)
08:18 <jle`> it's not really a "formal" definition, but if you think of an Applicative value as having 'effects', it means that <*>/liftA2/*>/<*/etc. have to be monoidal w.r.t. the effects
08:19 <jle`> i'm not sure how it relates to the day functor as a free applicative
08:19 <jle`> er, i mean, as a formulation
08:21 Linter joined
08:22 <bergle> this is the module afaik. http://hackage.haskell.org/package/checkers-0.4.10/docs/Test-QuickCheck-Checkers.html it is introduced in the book.
08:23 bergle joined
08:24 <bergle> oops fat fingered quit irc.
08:24 <bergle> http://hackage.haskell.org/package/checkers-0.4.10/docs/Test-QuickCheck-Classes.html has the applicative batch rule
08:26 <jle`> hmmmmm
08:26 <jle`> i wonder what's happening
08:26 <jle`> maybe it is using () for the type variables
08:27 <jle`> bergle: but yeah, try this example and see what the results are
08:28 <jle`> hm actually i have to think of an example
08:28 <jle`> but you might be able to mess around with some unequal length lists to get (xs *> ys) *> zs to not be xs *> (ys *> zs)
08:29 <bergle> :). i havnt even run '*>' on anything yet so dnt even know how it differs from <*>
08:29 <dminuoso> bergle: *> can be think of as an applicative const.
08:30 <jle`> <*> is like <*> but just ignores the values/results in the first item
08:30 <jle`> oops, accidentally added a <
08:30 <dminuoso> bergle: If you imagine fmapping `flip const` on the LHS and then <*> them together, that's *>
08:30 hphuoc25 joined
08:30 <dminuoso> bergle: while fmapping `const` on the LHS and then <*> two lists together, that's <*
08:31 <jle`> x <* y = fmap const x <*> y
08:32 <dminuoso> x *> fmap (flip const) x <*> y
08:32 <dminuoso> x *> y = fmap (flip const) x <*> y
08:34 louispan joined
08:35 nickolay_ joined
08:37 merijn joined
08:37 Pupnik joined
08:49 Folkol_ joined
08:53 dadabidet joined
08:55 hphuoc25 joined
09:02 louispan joined
09:03 rzp joined
09:09 louispan joined
09:22 hphuoc25 joined
09:29 b-b joined
09:30 fabsn joined
09:30 dadabidet joined
09:38 lumm joined
09:39 hphuoc25_ joined
09:50 lumm_ joined
09:52 louispan joined
09:53 Folkol_ joined
09:58 lumm_ joined
09:58 hphuoc25 joined
09:59 progfun joined
10:02 kmelva joined
10:08 curious_corn joined
10:10 machinedgod joined
10:13 vurtz joined
10:17 louispan joined
10:17 rockfruit joined
10:30 lumm_ joined
10:32 <bergle> Thanks for your input earlier, i think maybe i get why repeat or something equivalent is required in pure of Applicative ZipList'
10:35 matsurago joined
10:39 <bergle> i am a bit surprised i got the tests to pass lol ;)
10:47 <merijn> bergle: Well, there's a very simple test you can do to compare stuff
10:48 <merijn> bergle: "pure f <*> x" is supposed to be equivalent to "fmap f x", and, as you know "fmap id" is supposed to be equivalent to "id"
10:48 <merijn> So "pure id <*> x" should be equal to "x"
10:48 <merijn> bergle: So you can try using a different implementation of pure and try and see if that law still holds
10:48 <bergle> thats the core of where i finally understood the repeat bit.
10:49 <bergle> the weird thing is the compensation i had done in <*> covered most of it up lol.
10:49 <bergle> and let it past Test.QuickCheck.Class applicative test cases.
10:49 <bergle> pass.
10:51 Linter joined
10:53 TCZ joined
10:58 lumm joined
11:05 lumm joined
11:09 Folkol_ joined
11:13 louispan joined
11:15 cur8or joined
11:17 curious_corn joined
11:22 andreabedini joined
11:24 zero_byte joined
11:31 fabsn joined
11:35 curious_corn joined
11:35 cur8or joined
11:35 Folkol_ joined
11:35 malaclyps joined
11:40 curious_corn_ joined
11:43 pie_ joined
11:46 Arcaelyx_ joined
11:49 curious_corn joined
11:51 kapil___ joined
11:51 kueller_ joined
11:52 <kueller_> I realise this is a trivial thing, but I'm struggling with operators associativity and precedence and how they interract
11:53 <kueller_> a + b * c: since both + and * associate to the left, I would have read that as (a + b) + c. I understand that since * has higher priority than +, then it's actually read a + (b * c)
11:53 <kueller_> but how? does operator priority evaluation have priority over operator associativity?
11:55 <cppxor2arr> doesn't associativity kick in with operators of the same precedence?
11:55 <merijn> kueller_: associativity only applies when multiple operators of the same precedence are involved
11:56 <cppxor2arr> yeah
11:56 <kueller_> ah, I didn't know that. Need to think about it a bit
11:56 <kueller_> thanks!
11:56 <merijn> kueller_: So yes, precedence FIRST and associativity only if there's ambiguity after that (due to multiple operators with the same precedence)
11:56 <merijn> kueller_: Which is basically the same as all other programming languages do it, except that Haskell lets you define new ones
11:57 <cppxor2arr> you could say precedence has a higher precedence than asaociativity
11:57 <kueller_> merijn, it's also more important to understand in haskell (than in other languages I know) since most other languages are far more explicit about these things
11:58 <kueller_> eg scala: a.foo(b) is verbose but non-ambiguous
11:59 NotAChicken joined
11:59 <merijn> kueller_: I mean that in C, python, etc. + * / and other arithmetic behave the exact same way :)
11:59 <kueller_> which is why I'm trying to make absolutely sure I can read an haskell expression and not have doubts about how it's parsed
11:59 <kueller_> ah, right, yes :)
12:03 ThomasLocke joined
12:03 <ThomasLocke> I'm struggling to figure out how to write my FromJSON instances for this JSON: https://gist.github.com/ThomasLocke/45a22ebbcceea5ba33032c29aa2b8ab8
12:06 <ThomasLocke> gist updated with what I have now
12:07 <dminuoso> ThomasLocke: You write FromJSON not for "json" (which is just a format), but a data record instead.
12:07 <dminuoso> (or rather more generally any type)
12:08 <dminuoso> ThomasLocke: Also I do not understand what your comment is supposed to say. Can you share the actual code you tried for fromJSON, as well as the definition of the data type?
12:08 <ThomasLocke> Updated gist with my current Haskell types
12:09 <dminuoso> ThomasLocke: Does this code do what you want?
12:11 <cppxor2arr> is there a reason why haskell syntax highlighting is less colorful in lpaste than github's gist?
12:12 <dminuoso> cppxor2arr: they are different websites with different stylesheets and probably different code for syntax highlighting?
12:13 <cppxor2arr> :( gist requires signing in and lpaste doesn't. i guess lpaste highlighting looks ok
12:14 <dminuoso> cppxor2arr: You could also just sign up. ;-)
12:15 mcmuru joined
12:15 <cppxor2arr> i don't like staying signed in
12:15 <cppxor2arr> and can't
12:17 <ThomasLocke> dminuoso, The code solves the problem, all the "structure" just seems a bit excessive, when all I really need is a [Text] instead of the whole AppLog -> Applications -> appName thing.
12:17 <ThomasLocke> appLog = Just ["park", "log", "set", "intercept"] would be better
12:18 <ThomasLocke> If that makes sense
12:18 <ThomasLocke> :)
12:18 <dminuoso> ThomasLocke: I think I understand now.
12:18 <dminuoso> ThomasLocke: Let's start by making some type `newtype Apps' = Apps' [Text]'
12:20 <ThomasLocke> Done!
12:20 <ThomasLocke> So far so good. :D
12:21 <kueller_> merijn, would you say this is a fair description of how x O y P z is parsed?
12:21 <kueller_> - if O has higher priority than P: (x O y) P z
12:21 <kueller_> - otherwise, if O has lower priority than P: x O (y P z)
12:21 <kueller_> - otherwise, if O associates to the left: (x O y) P z
12:21 <kueller_> - otherwise: x O (y P z)
12:21 <dminuoso> ThomasLocke: So now your Cdr would look like `data Cdr = Cdr { apps :: !Apps', callFlowItems :: ![CallFlowItem], variables :: !Variables }
12:23 <dminuoso> ThomasLocke: So one way you could do this, is by then using the existing fromJSON instances you have, and using them for your `instance FromJSON Apps'`
12:24 <dminuoso> fromJSON = do { apps <- fromJSON @Application .: "applications"; pure (appName <$> apps) }
12:24 <dminuoso> Something along those lines perhaps
12:24 <dminuoso> (Im sure there are other ways, but this should work)
12:24 <ThomasLocke> How does this handle the Maybe part? Remember that app_log does not always exist
12:25 <dminuoso> ThomasLocke: If app_log does exist, is it always empty?
12:25 <dminuoso> ThomasLocke: Also I missed the Apps' wrapper
12:25 <dminuoso> so rather: pure . Apps' $ appName <$> apps
12:25 <ThomasLocke> If the "app_log" key is there, it is never empty. If it is not there, then well it isn't there.
12:25 <dminuoso> ThomasLocke: you could use the fact that a list can be empty then if you want.
12:26 <dminuoso> or use a `Maybe` with a NonEmpty
12:26 <ThomasLocke> If feel I'm venturing into areas beyond my paygrade
12:26 <ThomasLocke> aeson is not exactly easy for a Haskell beginner. :D
12:26 carlomagno joined
12:26 <dminuoso> :t fromJSON
12:26 <lambdabot> error: Variable not in scope: fromJSON
12:27 <dminuoso> @import Data.Aeson.FromJSON
12:27 <lambdabot> Unknown command, try @list
12:27 <dminuoso> @let import Data.Aeson.FromJSON
12:27 <lambdabot> .L.hs:65:1: error:
12:27 <lambdabot> Could not find module ‘Data.Aeson.FromJSON’
12:27 <lambdabot> Use -v to see a list of the files searched for.
12:27 <dminuoso> @let import Data.Aeson
12:27 <lambdabot> .L.hs:65:1: error:
12:27 <lambdabot> Data.Aeson: Can't be safely imported! The module itself isn't safe.
12:27 <lambdabot> |
12:27 <dminuoso> Oh well
12:28 <dminuoso> ThomasLocke: So let's take this one step at a time.
12:29 <dminuoso> ThomasLocke: You can use .:? instead of .: to denote the possibility of a key missing
12:30 <ThomasLocke> Yes, I'm already using that function for my Cdr type
12:30 <ThomasLocke> the appLog part that is
12:31 <dminuoso> ThomasLocke: Okay, so .:? at the end gives you a `Parser (Maybe a)`, so you can do something like:
12:31 Linter joined
12:31 <dminuoso> pure $ Cdr (fromMaybe [] appLog) callFlowItems variables
12:32 <dminuoso> Right?
12:33 progfun joined
12:33 <ThomasLocke> Yes.
12:34 <ThomasLocke> So how does that translate into FromJSON instances?
12:35 curious_corn joined
12:39 drbrule joined
12:40 hphuoc25 joined
12:42 <dminuoso> ThomasLocke: I think this should work https://gist.github.com/dminuoso/3d2a41f762d243aed85f7e3568d07044
12:42 <dminuoso> But you dont need that parseJSON really
12:43 <dminuoso> ThomasLocke: Do you really want a list there, or rather a Vector?
12:44 <ThomasLocke> I would literally never have come up with anything like your gist. It's suddenly very apparent that my Haskell/Aeson foo is very weak.. :D
12:44 <dminuoso> parseJSON = withArray "applications" $ \arr -> (.: "app_name") <$> arr
12:45 <dminuoso> Agnostic about the container even
12:45 <dminuoso> =)
12:45 <ThomasLocke> I'll do some experimenting. Thanks for the assist dminuoso
12:45 <dminuoso> parseJSON = withArray "applications" (fmap (.: "app_name"))
12:45 <ThomasLocke> hahaha
12:45 <ThomasLocke> You're destroying my brain
12:45 <dminuoso> ThomasLocke: Do you have some firm grasp on monads?
12:46 <ThomasLocke> I decidedly do not have a firm grasp on monads. Right now I treat them like contexts with magic
12:46 <dminuoso> ThomasLocke: So basically `Parser` is a monad. All that means is that you can use `do-notation`.
12:47 <dminuoso> <- runs the parser and gives you the result
12:47 <dminuoso> callerProfile <- o .: "caller_profile"
12:47 <ThomasLocke> That part I get
12:48 <dminuoso> ThomasLocke: This is a combinator that scans for a key "applications", expecting an array behind it. withArray "applications" $ \arr -> ...
12:49 <dminuoso> It gives you a `Vector Value` (note that the type "Array" is just an alias for this)
12:49 <dminuoso> And a `Vector Value` an efficient form of [Value]. If you are not comfortable with "Vector", just pretends its a fast list. =)
12:51 <dminuoso> so all you have to do, is figure out a way to turn `Vector Value` into what you want.
12:52 <dminuoso> Let's say we want to turn this into a `Vector Apps`.
12:52 <dminuoso> Or actually not `Vector Apps`, probably better just `Vector Text`
12:52 <dminuoso> So all we have to do now, is figure out a way how to turn a single `Value` into a `Text`
12:53 <dminuoso> That is, how do we turn some '{"app_name": "set","app_data": "intercept_unbridged_only=true","app_stamp": "1525422008179976"}' into "set"
12:53 <ThomasLocke> Do I need some special imports for you snippet to work? I'm getting some errors
12:53 <dminuoso> ThomasLocke: Getting there, its not meant to be used - just as an idea
12:54 <dminuoso> ThomasLocke: So all you have to do, is write a function that can do `Value -> Parser Text`
12:54 <dminuoso> ThomasLocke: Can you do that?
12:55 acarrico joined
12:55 <ThomasLocke> I'll give it a whirl for sure.. I have a sneaking suspicion that I'll be right proper tired tonight. hahahaha
12:55 <dminuoso> ThomasLocke: Lets reapproach from the beginning I think I overcomplicated things. This is really not hard =)
12:56 <dminuoso> The endgoal is to have some `fromJSON :: Value -> Cdr` right?
12:56 <dminuoso> Err
12:57 <dminuoso> fromJSON :: Value -> Parser Cdr
12:58 <ThomasLocke> Sounds about right, except in my head I'm trying to transform a json string into a Cdr type
12:58 <ThomasLocke> Which I'm doing right now, I just don't like the structure of the app_log part
12:58 <dminuoso> ThomasLocke: https://gist.github.com/dminuoso/3d2a41f762d243aed85f7e3568d07044
12:58 <dminuoso> So lets start from here.
12:59 <dminuoso> ThomasLocke: This is what we want. All we want, is to figure out how to write `foo`
13:02 <dminuoso> ThomasLocke: Because we want to parse a JSON array, we will use the `withArray` helper to build a parser that does this
13:02 <dminuoso> Just staring the type: withArray :: String -> (Array -> Parser a) -> Value -> Parser a
13:02 <merijn> kueller_: That's looks accurate enough at first glance, yeah
13:03 <dminuoso> ThomasLocke: The first parameter is the attribute to look for. withArray will then create an array of "unknown" values and use our function to figure out what to do with that array
13:04 <dminuoso> ThomasLocke: it then needs a Value, so we need to pass the `o` from our fromJSON through. I've made the necessary modifications to the gist to show you what it looks like now
13:04 <kueller_> merijn, thanks! I think it's pretty clear now
13:05 <dminuoso> ThomasLocke: is this clear so far?
13:05 <ThomasLocke> dminuoso, o is an Object, not a Value
13:05 <ThomasLocke> And yes, I'm with you so far.
13:06 <ThomasLocke> So in foo we then query to see if the app_log key is there and if so, then drill further down to get to the applications list and then finally the app_name strings?
13:07 <dminuoso> ThomasLocke: Oh wait I misread this. Let me fix this =)
13:08 Cale_ joined
13:09 <dminuoso> ThomasLocke: Ive updated to correct for that gross mistake :)
13:09 <dminuoso> ThomasLocke: Does this make sense?
13:09 <ThomasLocke> What is that "attributes" thing?
13:10 <dminuoso> isnt that the property? or was it applications?
13:10 <ThomasLocke> app_log is the outermost key
13:10 <ThomasLocke> Which is only there occasionally, so it's a Maybe I guess?
13:11 <ThomasLocke> Or it's just always there as a [Text], which can then just be empty, yes?
13:11 <dminuoso> ThomasLocke: Lets for now pretend its there, and address this afterwards.
13:11 <dminuoso> ThomasLocke: So `app_log` contains an object we want to look into
13:11 <dminuoso> so we need some withObject first
13:12 <dminuoso> ThomasLocke: are you comfortable with me removing the `v` parameter on both ends? (eta reduction)
13:12 djtyml joined
13:13 <ThomasLocke> yes
13:15 <dminuoso> ThomasLocke: Updated gist. So now we just pull the `apps` out, which is again some Value
13:16 <dminuoso> ThomasLocke: so now we want to treat that as an array, so we now use withArray on the result.
13:16 curious_corn_ joined
13:17 <ThomasLocke> It should be Maybe Value for the first getInnerTexts param yes?
13:17 <dminuoso> ThomasLocke: In the current version you have `arr :: Vector Value`
13:18 <dminuoso> ThomasLocke: Yeah. Or you could use `maybe`
13:18 <dminuoso> :t maybe
13:18 <lambdabot> b -> (a -> b) -> Maybe a -> b
13:19 <dminuoso> Reload to see
13:19 <dminuoso> So all we have to do, is figure out how to turn `Vector Value` into `Parser [Text]`
13:20 <ThomasLocke> throws a bunch of "could not match..." errors now
13:21 <ThomasLocke> Couldn't match expected type ‘Value’ with actual type ‘Maybe a0’
13:21 iAmerikan joined
13:22 <ThomasLocke> maybe (pure []) getInnerTexts apps
13:22 <ThomasLocke> Seems to fix it
13:24 <dminuoso> ThomasLocke: So all we are left with, is a way to parse that final object into the string
13:24 <dminuoso> And we can just use .: for that
13:24 <dminuoso> For any single v :: Value, we would just do `v .: "app_name"` to build the appropriate parser right?
13:25 <ThomasLocke> Yes
13:25 <dminuoso> But we don't have a single Value, we have a `Vector Value`
13:25 <ThomasLocke> That sounds right
13:25 <dminuoso> So what we do instead is use `traverse` or `for`/`forM`
13:25 <ThomasLocke> So I need to import the vector stuff correct?
13:26 <dminuoso> ThomasLocke: You will yes.
13:26 <dminuoso> ThomasLocke: So first lets consider a function that makes each value to a parser
13:27 <dminuoso> \x -> x .: "app_name"
13:27 <dminuoso> We can rewrite that as a section: (.: "app_name")
13:28 <ThomasLocke> Gotcha
13:28 <dminuoso> So now we just traverse with that function over the Vector
13:28 <dminuoso> traverse (.: "app_name") arr
13:28 djtyml_ joined
13:28 andreabedini joined
13:29 <dminuoso> Which gives you some `FromJSON a => Vector (Parser a)`
13:29 djtyml__ joined
13:29 <dminuoso> Which gives you some `FromJSON a => Parser (Vector a)`
13:29 <dminuoso> = P
13:29 <dminuoso> Through type annotations, type applications or inference it can infer that `a` needs to be Text
13:30 <dminuoso> And if you want a list intsead of a vector you fmap over that with `toList`
13:31 <dminuoso> ThomasLocke: gist updated to reflect latest changes.
13:33 <ThomasLocke> Throws a bunch of errors at me
13:33 pbrant joined
13:33 <ThomasLocke> Dumped in gist
13:33 djtyml joined
13:33 <dminuoso> ThomasLocke: Oh heh I think you caught it in the wrong moment when I was golfing around
13:35 <ThomasLocke> Hmm.. the traverse function - where's that from?
13:35 <ThomasLocke> Maybe I'm getting errors because I don't have that imported?
13:36 <ThomasLocke> Also I need to change the Cdr type to now have V.Vector Text instead of [Text] correct?
13:41 <dminuoso> ThomasLocke: https://gist.github.com/dminuoso/6c9bca7c9b8f2c26c450b5d6c0d463f5
13:41 <dminuoso> ThomasLocke: I checked it and it seems to work.
13:42 <ThomasLocke> some of the errors went away when I replaced (pure []) with (pure V.empty)
13:42 <dminuoso> ThomasLocke: Well how large can these things become?
13:42 <dminuoso> And do you always need the entire log?
13:42 <ThomasLocke> getInnerTexts still doesn't type check
13:42 <dminuoso> ThomasLocke: Check the gist I linked a few seconds ago
13:42 <ThomasLocke> Yup, I need the entire log
13:43 <dminuoso> ThomasLocke: How large can they get?
13:43 <ThomasLocke> I don't mind using vectors. I'm not married to [Text].. Vector Text is fine, if that simplifies things
13:44 <dminuoso> ThomasLocke: It doesnt make much of a difference, but Vector certainly cant hurt :)
13:44 <ThomasLocke> I guessed you were worried about the size due to the V.toList function?
13:44 <dminuoso> ThomasLocke: https://gist.github.com/dminuoso/6c9bca7c9b8f2c26c450b5d6c0d463f5
13:45 <dminuoso> ThomasLocke: lists perform quite horrible in some metrics (random access, scanning, memory consumption)
13:45 <ThomasLocke> So I've heard. :o)
13:46 <dminuoso> ThomasLocke: you dont need to use withArray/withObject by the way. They are just simple helpers that pattern match against Value and fail the parser
13:47 <dminuoso> (that is, there's no deep magic)
13:48 <dminuoso> ThomasLocke: Also if you dont like the kleisli composition, you can write it out with do-notation
13:49 <ThomasLocke> dminuoso, Ooook.. I can get rid of withObject and withArray? Just remove them?
13:49 <dminuoso> ThomasLocke: You shouldn't. My point is they are not "special"
13:49 Linter joined
13:49 <dminuoso> ThomasLocke: `data Value = Object !Object | Array !Array | String !Text | Number !Scientific | Bool !Bool | Null`
13:49 <ThomasLocke> dminuoso, This. Just. Works. It does EXACTLY what I need.. My goodness man! Thanks!
13:50 <ThomasLocke> My mind is boggled
13:50 <dminuoso> ThomasLocke: So `withObject` is a simple "filter" that only lets object through (and fails the parser if there's no object)
13:52 jsondavis joined
13:52 lumm joined
13:52 <ThomasLocke> Ahh.. Clever
13:52 <dminuoso> ThomasLocke: You can think of `withObject` as a kind of "casting" from Value to Object =)
13:53 <dminuoso> and withArray as a kind of "casting" from Value to Array
13:53 <dminuoso> and so forth
13:54 <ThomasLocke> That makes sense.
13:55 <ThomasLocke> I'll be studying this for a while. There's a lot to Aeson
13:55 barcabuona joined
13:55 <dminuoso> ThomasLocke: You might want to rewrite without kleisli composition if you dont like it.
13:55 <dminuoso> ThomasLocke: https://gist.github.com/dminuoso/6c9bca7c9b8f2c26c450b5d6c0d463f5
13:55 <ThomasLocke> That's all part of the "studying" part. I don't know if I'll like before if looked at it for a while. hehe
13:56 <dminuoso> ThomasLocke: It's basically like function composition
13:56 <dminuoso> If you have some `a -> m b` and some `b -> m c` for some Monad m, it composes them into `a -> m c`
13:57 <dminuoso> its equivalent to "pulling" the result from some monadic action with <- and fiddling it into the next line as the last argument
13:58 justaguest joined
13:58 <ThomasLocke> That's pretty clever
13:58 progfun joined
13:59 <ThomasLocke> I've fiddled a bit with >>= and >>
13:59 <ThomasLocke> The "fish" seems to live in the same space. :)
13:59 <dminuoso> ThomasLocke: It'
13:59 <dminuoso> ThomasLocke: It's function composition except for things that somehow have this m in the way =)
14:00 <dminuoso> (f . g) creates a function that fiddles the result of g into f
14:00 <dminuoso> (f <=< g) creates a function that fiddles the monadic action result of g into f
14:01 <dminuoso> (Using >>=)
14:01 <ThomasLocke> It takes a bit of time to learn to read all of those "weird" functions.
14:02 <dminuoso> Yeah like I said. Its fine if you are not comfortable with it.
14:02 <dminuoso> ThomasLocke: https://gist.github.com/dminuoso/6c9bca7c9b8f2c26c450b5d6c0d463f5
14:02 <dminuoso> I put them put both in for comparison
14:03 <ThomasLocke> So sweet. Thanks again. This was a huge help.
14:07 curious_corn joined
14:08 lumm joined
14:09 dibblego joined
14:09 dibblego joined
14:11 pie_ joined
14:15 zero_byte joined
14:19 pie_ joined
14:27 Folkol_ joined
14:33 sheyll joined
14:38 hphuoc25 joined
14:41 hyperisco joined
14:48 justaguest joined
15:07 zaquest joined
15:13 cschneid joined
15:15 Folkol_ joined
15:23 cur8or joined
15:27 skeet70 joined
15:29 progfun joined
15:34 cur8or_ joined
15:37 hphuoc25 joined
15:38 pfurla joined
15:38 mounty joined
15:49 emilypi joined
16:03 obi_jan_kenobi__ joined
16:03 <chindy> Is it possible/good practice to transform Maybe String to IO String ? if so how?
16:05 <glguy> chindy: What would that do?
16:18 Linter joined
16:23 justaguest joined
16:24 pfurla joined
16:28 lumm joined
16:31 machined1od joined
16:35 vurtz joined
16:35 <joel135> :t maybe (error "nothing!") pure
16:35 <lambdabot> Applicative f => Maybe a -> f a
16:38 <joel135> :t maybe (fail "bad day") pure
16:38 <lambdabot> Monad m => Maybe a -> m a
16:41 <dminuoso> :t flip maybe pure . throwIO
16:41 <lambdabot> Exception e => e -> Maybe a -> IO a
16:41 <dminuoso> joel135: ^- this might seem preferrable :)
16:44 <joel135> Ok :)
16:44 <dminuoso> joel135: Though you might want to rethink what you are doing entirely.
16:45 <dminuoso> joel135: You tried to make Nothing disappear entirely by throwing in pure code which doesn't sound like a good thing. What is the goal?
16:46 hphuoc25 joined
16:49 asMyCookieCrumbl joined
16:49 obi_jan_kenobi joined
16:55 fabsn joined
17:01 hiratara joined
17:06 lumm joined
17:10 lumm joined
17:10 <pie_> not really a haskell specific question just thought someone here might be well equipped to answer; ive been meaning to get into UI development since it seems like an area that could use a lot of improvement, but i havent really been able to figure out how to get started (*im interested in native apps, not browser stuff)
17:15 Gurkenglas joined
17:19 bbrodriguez joined
17:20 bbrodriguez joined
17:22 replay joined
17:24 bbrodriguez joined
17:25 nitrix joined
17:26 nitrix joined
17:26 shafox joined
17:37 pfurla joined
17:37 bbrodriguez joined
17:46 chrisdotcode joined
17:49 iAmerikan joined
17:49 lumm joined
17:50 replay joined
17:54 bbrodriguez joined
18:02 lumm joined
18:12 iAmerika1 joined
18:17 curious_corn joined
18:29 curious_corn joined
18:34 hphuoc25 joined
18:49 Linter joined
19:00 delexi joined
19:02 xpycm joined
19:02 curious_corn joined
19:10 Deide joined
19:21 curious_corn joined
19:31 iAmerika1 joined
19:40 dxld joined
19:50 dxld joined
20:06 replay joined
20:12 jsondavis joined
20:14 hphuoc25 joined
20:16 iAmerika1 joined
20:16 lumm joined
20:25 lumm joined
20:29 kapil___ joined
20:30 kmelva joined
20:32 jsondavis joined
20:33 aarvar joined
20:44 merijn joined
21:07 kaictl joined
21:08 <jle`> chindy: do not use error or fail
21:08 <jle`> er, fail might be minimally ok
21:08 <jle`> chindy: but the most straightforward way would be pattern matching
21:08 <jle`> chindy: that forces you to think about what you want to do to handle the Nothing case
21:10 louispan joined
21:14 <glguy> The question ended up getting covered on #haskell
21:14 <glguy> it ended up being a different question, not about various ways to fail that people proposed here
21:16 iAmerikan joined
21:19 <jle`> good to hear :)
21:20 Linter joined
21:23 Ariakenom joined
21:28 iAmerika1 joined
21:30 <pie_> i wonder how hard it would be to make bindings for https://github.com/ocornut/imgui
21:38 <merijn> jle`: You forgot "don't use throw"
21:38 zero_byte joined
21:39 <jle`> ^^
21:53 hiratara joined
22:09 Gurkenglas joined
22:11 dxld joined
22:17 AndreasK joined
22:31 hiratara joined
22:31 Sose joined
22:32 tnks joined
22:33 hamishmack joined
22:42 Arcaelyx joined
23:12 Linter joined
23:22 _ikke_ joined
23:42 dogweather joined
23:47 pfurla joined
23:47 fabsn joined
23:49 _ikke_ joined
23:59 louispan joined