Logs: freenode/#haskell
| 2020-11-20 21:38:49 | → | mputz joins (~Thunderbi@dslb-084-058-211-084.084.058.pools.vodafone-ip.de) |
| 2020-11-20 21:41:03 | <jcd> | So, I see that it is a valid choice! I don't know if it's the one I _should_ choose though. |
| 2020-11-20 21:41:03 | → | conal joins (~conal@172.255.125.150) |
| 2020-11-20 21:42:21 | × | nyaomi quits (~naomi@2604:6000:1509:c86e:c878:29ff:fedf:ce89) (Quit: meow) |
| 2020-11-20 21:42:22 | × | geekosaur quits (ac3a56ed@172.58.86.237) (Remote host closed the connection) |
| 2020-11-20 21:42:28 | <dminuoso> | That's up to you. In this case, the idea is "parseRequest" could fail. Rather than forcing the function to use say `Maybe` or `IO` to communicate failure in, it defers the choice to you. |
| 2020-11-20 21:42:51 | <sm[m]> | interactively inspect Haskell values at runtime ... that's interesting |
| 2020-11-20 21:42:51 | <dminuoso> | It says "Hey, you pick something of type `m`, as long as I can throw an exception with it", for some value of "exception" |
| 2020-11-20 21:43:23 | <sm[m]> | doc: https://hackage.haskell.org/package/heap-console-0.1.0.0/docs/Heap-Console.html |
| 2020-11-20 21:45:08 | <dminuoso> | Internally the package will use `throwM (InvalidUrlException s "Invalid URL")` if it failed to parse your input. What this ends up doing depends on your choice, if you pick Maybe, you get a Nothing back. |
| 2020-11-20 21:45:12 | → | justanotheruser joins (~justanoth@unaffiliated/justanotheruser) |
| 2020-11-20 21:45:19 | <dminuoso> | If you pick IO, you get an IO exception |
| 2020-11-20 21:45:27 | <dminuoso> | And so forth |
| 2020-11-20 21:45:30 | hackage | predicate-typed 0.7.4.5 - Predicates, Refinement types and Dsl https://hackage.haskell.org/package/predicate-typed-0.7.4.5 (gbwey) |
| 2020-11-20 21:46:09 | <jcd> | Okay! Got it! How would I properly wrap it? Is there an approriate place to show a 3-line code example? |
| 2020-11-20 21:46:20 | <dminuoso> | What do you mean with "wrap it"? |
| 2020-11-20 21:46:25 | → | nyaomi joins (~naomi@cpe-74-75-6-125.maine.res.rr.com) |
| 2020-11-20 21:46:27 | <dminuoso> | @where paste |
| 2020-11-20 21:46:27 | <lambdabot> | Help us help you: please paste full code, input and/or output at eg https://paste.tomsmeding.com |
| 2020-11-20 21:47:10 | <jcd> | https://paste.tomsmeding.com/5trqeFMa |
| 2020-11-20 21:47:35 | <jcd> | Would it be better to say 'assign'? |
| 2020-11-20 21:47:59 | <dminuoso> | jcd: I see. So since httpLbs puts you into IO already, you could chose IO for parseRequest too |
| 2020-11-20 21:48:38 | <dminuoso> | Also note that this use of `Maybe` is not valid |
| 2020-11-20 21:48:50 | <dminuoso> | Sadly, there's not a very explicit way to make the choice, it is inferred on usage |
| 2020-11-20 21:48:52 | <dminuoso> | Say, if you wrote: |
| 2020-11-20 21:49:12 | → | johnw_ joins (~johnw@haskell/developer/johnw) |
| 2020-11-20 21:49:14 | → | minimario joins (2fe3e53b@047-227-229-059.res.spectrum.com) |
| 2020-11-20 21:49:18 | → | hlisp joins (~hlisp@114.246.35.11) |
| 2020-11-20 21:49:22 | <dminuoso> | let f :: Maybe Request; f = parseRequest "https://google.de" in ... |
| 2020-11-20 21:49:38 | <dminuoso> | Then the choice is made in the type signature. Equivalently if you wrote: |
| 2020-11-20 21:49:49 | <dminuoso> | case parseRequest "https://google.de" of |
| 2020-11-20 21:49:51 | <dminuoso> | Nothing -> ... |
| 2020-11-20 21:49:54 | <dminuoso> | Just x -> ... |
| 2020-11-20 21:49:57 | → | gxt joins (~gxt@gateway/tor-sasl/gxt) |
| 2020-11-20 21:50:19 | × | heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Remote host closed the connection) |
| 2020-11-20 21:50:21 | <dminuoso> | Then the choice is implicit because GHC can infer Maybe from the data constructors in the pattern matching. |
| 2020-11-20 21:51:07 | <dminuoso> | For your case, IO is probably a fine choice. Then you can just write: https://paste.tomsmeding.com/USndzrdo |
| 2020-11-20 21:51:20 | <dminuoso> | (The choice of IO is inferred based on the context automatically) |
| 2020-11-20 21:51:56 | × | ubert quits (~Thunderbi@p200300ecdf1e5361e6b318fffe838f33.dip0.t-ipconnect.de) (Remote host closed the connection) |
| 2020-11-20 21:52:31 | hackage | phonetic-languages-simplified-common 0.2.1.0 - A simplified version of the phonetic-languages-functionality https://hackage.haskell.org/package/phonetic-languages-simplified-common-0.2.1.0 (OleksandrZhabenko) |
| 2020-11-20 21:52:43 | <jcd> | Because of the 'do'! |
| 2020-11-20 21:52:50 | <dminuoso> | no, not the do |
| 2020-11-20 21:52:54 | <jcd> | Oh! |
| 2020-11-20 21:52:59 | <jcd> | the '<-' |
| 2020-11-20 21:53:04 | <dminuoso> | Also, no. |
| 2020-11-20 21:53:12 | <dminuoso> | If you keep guessing, you'll eventually figure it out. |
| 2020-11-20 21:53:14 | <dminuoso> | :) |
| 2020-11-20 21:53:25 | <dminuoso> | Well, the `do` notation is related, but not quite the point |
| 2020-11-20 21:53:33 | <minimario> | quick question: what's the logic behind making andM return Just False instead of Nothing when we call it on andM (Just False) Nothing? |
| 2020-11-20 21:53:45 | × | hlisp quits (~hlisp@114.246.35.11) (Ping timeout: 260 seconds) |
| 2020-11-20 21:54:16 | → | elliott__ joins (~elliott@pool-108-51-141-12.washdc.fios.verizon.net) |
| 2020-11-20 21:54:50 | <dminuoso> | jcd: https://paste.tomsmeding.com/Xx49wa4s here there's two points of interest. |
| 2020-11-20 21:55:04 | ski | . o O ( <https://hackage.haskell.org/package/hood>,<https://hackage.haskell.org/package/GHood>,<https://wiki.haskell.org/Debugging#Printf_and_friends> ) |
| 2020-11-20 21:55:40 | <dminuoso> | jcd: First there's the type signature telling us the do-notation uses IO. You left it out, which gives us another point of inference |
| 2020-11-20 21:55:44 | <dminuoso> | The type of httpLbs |
| 2020-11-20 21:56:15 | <jcd> | Since the httpLbs is the expression that gets returned? |
| 2020-11-20 21:56:27 | <dminuoso> | Not because it's returned, just its presence. |
| 2020-11-20 21:56:33 | <dminuoso> | It could be on any line in the do block, in fact. |
| 2020-11-20 21:56:50 | <dminuoso> | Roughly, do-notation is just a syntax desugarer |
| 2020-11-20 21:57:15 | <dminuoso> | It desugars uses of line breaks and <- into (>>) and (>>=) |
| 2020-11-20 21:57:32 | <dminuoso> | % :t (>>) |
| 2020-11-20 21:57:33 | <yahb> | dminuoso: Monad m => m a -> m b -> m b |
| 2020-11-20 21:57:34 | <dminuoso> | % :t (>>+) |
| 2020-11-20 21:57:35 | <yahb> | dminuoso: ; <interactive>:1:1: error:; * Variable not in scope: >>+; * Perhaps you meant one of these: `>>=' (imported from Prelude), `>>' (imported from Prelude), `>>>' (imported from Control.Arrow) |
| 2020-11-20 21:57:37 | <dminuoso> | % :t (>>=) |
| 2020-11-20 21:57:37 | <yahb> | dminuoso: Monad m => m a -> (a -> m b) -> m b |
| 2020-11-20 21:57:41 | <ski> | minimario : it's short-circuiting. since the first action (successfully) executes to `False', we abort and don't try the second |
| 2020-11-20 21:57:56 | <dminuoso> | jcd: Do you see in each type, there's multiple occurences of the *same* m? |
| 2020-11-20 21:58:35 | → | rprije joins (~rprije@124.148.131.132) |
| 2020-11-20 21:58:42 | <dminuoso> | jcd: Recall, same story as above! This is a polymorphic value, *you* decide what you want for each of those type variables. So if you make the choice `IO` for the first `m` in say (>>=), then the other `m` in (>>=) become IO too. |
| 2020-11-20 21:58:54 | <ski> | minimario : similarly, if you did `andM readLn readLn', and you typed in `False' for the first one, it would abort the `andM', and not try executing the second `readLn' |
| 2020-11-20 21:59:45 | <dminuoso> | jcd: It's roughly similar to if you had `a + b + c + d`, and if `a` was of type Int, then `b`, `c` and `d` have to be of type Int. |
| 2020-11-20 21:59:51 | <dminuoso> | % :t (+) |
| 2020-11-20 21:59:51 | <yahb> | dminuoso: Num a => a -> a -> a |
| 2020-11-20 21:59:52 | <ski> | minimario : if you don't want short-circuiting, you can use `liftM2 (&&)'/`liftA2 (&&)'. but the point here was exactly when you want short-circuiting |
| 2020-11-20 22:00:18 | <jcd> | dminuoso: Yeah, I do! That explains the errors my REPL was dumping out. |
| 2020-11-20 22:00:45 | × | takuan quits (~takuan@178-116-218-225.access.telenet.be) (Ping timeout: 240 seconds) |
| 2020-11-20 22:01:08 | <jcd> | dminuoso: Thank you so much for the help! Recommend any literature so I don't have cry anymore. |
| 2020-11-20 22:01:27 | <minimario> | ski: ah ok that makes sense |
| 2020-11-20 22:01:40 | <ski> | @hoogle Monad m => (a -> m Bool) -> [a] -> m Bool |
| 2020-11-20 22:01:41 | <lambdabot> | Control.Monad.Extra anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool |
| 2020-11-20 22:01:41 | <lambdabot> | Control.Monad.Extra allM :: Monad m => (a -> m Bool) -> [a] -> m Bool |
| 2020-11-20 22:01:41 | <lambdabot> | Extra anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool |
| 2020-11-20 22:01:50 | <ski> | @hoogle Monad m => [m Bool] -> m Bool |
| 2020-11-20 22:01:51 | <lambdabot> | Control.Monad.Extra orM :: Monad m => [m Bool] -> m Bool |
| 2020-11-20 22:01:51 | <lambdabot> | Control.Monad.Extra andM :: Monad m => [m Bool] -> m Bool |
| 2020-11-20 22:01:51 | <lambdabot> | Extra orM :: Monad m => [m Bool] -> m Bool |
| 2020-11-20 22:01:56 | <ski> | similar thing, in those |
| 2020-11-20 22:02:17 | × | johnw_ quits (~johnw@haskell/developer/johnw) (Quit: ZNC - http://znc.in) |
| 2020-11-20 22:02:23 | <ski> | minimario : ooc, which module were you looking in ? |
| 2020-11-20 22:02:27 | <dminuoso> | jcd: Im not good on book references. I keep suggesting CIS194 because it's the only reference material I looked at in the past 12 months and it looked decent. |
| 2020-11-20 22:02:53 | <dminuoso> | And it happens to be one of the few resources that's not as dated |
| 2020-11-20 22:02:58 | → | borne joins (~fritjof@200116b86455d000f1dc39039d201adf.dip.versatel-1u1.de) |
| 2020-11-20 22:03:16 | × | invaser quits (~Thunderbi@31.148.23.125) (Ping timeout: 272 seconds) |
| 2020-11-20 22:03:21 | <ski> | @where CIS194 |
| 2020-11-20 22:03:21 | <lambdabot> | https://www.seas.upenn.edu/~cis194/spring13/lectures.html |
| 2020-11-20 22:03:43 | <minimario> | oh lol i was just doing an intro haskell tutorial and one of the exercises was to implement andM haha |
| 2020-11-20 22:03:44 | <dminuoso> | There's also a more recent version of CIS194 from Joachim Breitner around, the style is slightly different. |
| 2020-11-20 22:03:45 | → | hlisp joins (~hlisp@114.246.35.11) |
| 2020-11-20 22:03:51 | <dminuoso> | https://www.seas.upenn.edu/~cis194/fall16/ |
All times are in UTC.