Logs: liberachat/#haskell
| 2021-07-19 08:06:37 | → | hendursa1 joins (~weechat@user/hendursaga) |
| 2021-07-19 08:09:39 | × | hendursaga quits (~weechat@user/hendursaga) (Ping timeout: 244 seconds) |
| 2021-07-19 08:11:35 | → | Gurkenglas joins (~Gurkengla@dslb-002-203-144-156.002.203.pools.vodafone-ip.de) |
| 2021-07-19 08:12:29 | × | shriekingnoise quits (~shrieking@186.137.144.80) (Quit: Quit) |
| 2021-07-19 08:17:32 | → | drd joins (~drd@93-39-151-19.ip76.fastwebnet.it) |
| 2021-07-19 08:17:34 | → | allbery_b joins (~geekosaur@xmonad/geekosaur) |
| 2021-07-19 08:20:06 | × | brandon quits (~geekosaur@xmonad/geekosaur) (Ping timeout: 255 seconds) |
| 2021-07-19 08:24:49 | → | MQ-17J joins (~MQ-17J@d14-69-206-129.try.wideopenwest.com) |
| 2021-07-19 08:28:39 | → | Lord_of_Life_ joins (~Lord@user/lord-of-life/x-2819915) |
| 2021-07-19 08:30:00 | × | tzh quits (~tzh@c-24-21-73-154.hsd1.or.comcast.net) (Quit: zzz) |
| 2021-07-19 08:31:05 | × | Lord_of_Life quits (~Lord@user/lord-of-life/x-2819915) (Ping timeout: 255 seconds) |
| 2021-07-19 08:31:17 | Lord_of_Life_ | is now known as Lord_of_Life |
| 2021-07-19 08:31:49 | × | MQ-17J quits (~MQ-17J@d14-69-206-129.try.wideopenwest.com) (Ping timeout: 246 seconds) |
| 2021-07-19 08:33:21 | × | merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 265 seconds) |
| 2021-07-19 08:36:14 | → | MQ-17J joins (~MQ-17J@d14-69-206-129.try.wideopenwest.com) |
| 2021-07-19 08:37:16 | × | chris_ quits (~chris@81.96.113.213) (Remote host closed the connection) |
| 2021-07-19 08:38:19 | × | ChaiTRex quits (~ChaiTRex@user/chaitrex) (Remote host closed the connection) |
| 2021-07-19 08:38:45 | → | ChaiTRex joins (~ChaiTRex@user/chaitrex) |
| 2021-07-19 08:40:12 | × | lavaman quits (~lavaman@98.38.249.169) (Remote host closed the connection) |
| 2021-07-19 08:40:24 | → | lavaman joins (~lavaman@98.38.249.169) |
| 2021-07-19 08:40:32 | × | lavaman quits (~lavaman@98.38.249.169) (Remote host closed the connection) |
| 2021-07-19 08:41:04 | → | lavaman joins (~lavaman@98.38.249.169) |
| 2021-07-19 08:45:23 | → | davros joins (~davros@host86-185-61-40.range86-185.btcentralplus.com) |
| 2021-07-19 08:47:17 | → | guest719 joins (~user@49.5.6.87) |
| 2021-07-19 08:47:39 | → | lars8 joins (~bc817c21@217.29.117.252) |
| 2021-07-19 08:48:19 | <guest719> | why `traverse` would immediatly exit when it meet a Left a? |
| 2021-07-19 08:48:51 | <guest719> | traverse (\i -> if odd i then Right () else Left i) [1..10] |
| 2021-07-19 08:49:42 | <lars8> | > traverse (\i -> if odd i then Right () else Left i) [1..10] |
| 2021-07-19 08:49:44 | <lambdabot> | Left 2 |
| 2021-07-19 08:51:41 | <lars8> | > sequence [Left 1, Right 2] |
| 2021-07-19 08:51:42 | <lambdabot> | Left 1 |
| 2021-07-19 08:51:46 | <lars8> | @src sequence |
| 2021-07-19 08:51:46 | <lambdabot> | sequence [] = return [] |
| 2021-07-19 08:51:46 | <lambdabot> | sequence (x:xs) = do v <- x; vs <- sequence xs; return (v:vs) |
| 2021-07-19 08:51:46 | <lambdabot> | --OR |
| 2021-07-19 08:51:46 | <lambdabot> | sequence xs = foldr (liftM2 (:)) (return []) xs |
| 2021-07-19 08:52:00 | <lars8> | does that help? |
| 2021-07-19 08:52:50 | <lars8> | traverse f is basically sequence . map f |
| 2021-07-19 08:53:22 | <guest719> | but why it meet Left a will early exit? |
| 2021-07-19 08:53:48 | <lars8> | because that's what liftM2 does |
| 2021-07-19 08:54:04 | <guest719> | @src liftM2 |
| 2021-07-19 08:54:04 | <lambdabot> | liftM2 f m1 m2 = do |
| 2021-07-19 08:54:04 | <lambdabot> | x1 <- m1 |
| 2021-07-19 08:54:05 | <lambdabot> | x2 <- m2 |
| 2021-07-19 08:54:05 | <lambdabot> | return (f x1 x2) |
| 2021-07-19 08:54:23 | <lars8> | > liftM2 (+) (Right 1) (Right 2) |
| 2021-07-19 08:54:25 | <lambdabot> | Right 3 |
| 2021-07-19 08:54:35 | <lars8> | > liftM2 (+) (Right 1) (Left 2) |
| 2021-07-19 08:54:36 | <lambdabot> | Left 2 |
| 2021-07-19 08:54:48 | <dminuoso> | guest719: `Either a`, like `Maybe`, models computations with exceptions. |
| 2021-07-19 08:55:07 | <dminuoso> | So a `Left err` or `Nothing` has the same semantics as an exception, it shortcircuits the entire computation |
| 2021-07-19 08:55:12 | <lars8> | if any argument is Left, entire computation is Left |
| 2021-07-19 08:55:17 | <guest719> | oh, Left 2 will break the computation chain in >>= |
| 2021-07-19 08:55:21 | <dminuoso> | Yes. |
| 2021-07-19 08:55:52 | <guest719> | dminuoso and why it's that? define in >>= ? |
| 2021-07-19 08:55:55 | <dminuoso> | guest719: Yes. |
| 2021-07-19 08:56:26 | <dminuoso> | The applicative and monadic interface of `Maybe` and `Either s` simply models exceptions. |
| 2021-07-19 08:56:27 | <guest719> | dminuoso except Left a and Nothing, is there other would break computation chain? |
| 2021-07-19 08:56:30 | <dminuoso> | There's no deeper reason than that. |
| 2021-07-19 08:56:37 | → | Erutuon joins (~Erutuon@user/erutuon) |
| 2021-07-19 08:56:39 | <dminuoso> | Sure there are others |
| 2021-07-19 08:56:46 | <guest719> | for examples? |
| 2021-07-19 08:57:06 | <dminuoso> | ExceptT |
| 2021-07-19 08:57:19 | <dminuoso> | Though that's just an `Either s` in disguise |
| 2021-07-19 08:57:36 | <guest719> | I can't help when you said Exception, I always think about run-time Exceptions |
| 2021-07-19 08:57:48 | <dminuoso> | Yes, these are pretty much like runtime exceptions! |
| 2021-07-19 08:57:51 | <dminuoso> | Consider: |
| 2021-07-19 08:57:53 | <guest719> | why haskell would give it another name |
| 2021-07-19 08:58:02 | <dminuoso> | These are value-level/user-defined exceptions |
| 2021-07-19 08:58:02 | <guest719> | wouldn't |
| 2021-07-19 08:58:38 | <dminuoso> | guest719: We also have regular RTS exceptions as you know them inside IO. |
| 2021-07-19 08:58:48 | <dminuoso> | But in pure computations it might still be useful to have shortcircuiting semantics |
| 2021-07-19 08:58:57 | <dminuoso> | Like with traverse. |
| 2021-07-19 08:59:18 | <dminuoso> | Say you have a tree, and you want to process each node - but in a way that if you generate an error at any, that the entire computation is considered failed. |
| 2021-07-19 08:59:46 | <dminuoso> | Then you can use `Maybe` or `Either s` (depending on whether you want to keep information about the error condition) |
| 2021-07-19 09:00:06 | <dminuoso> | Then producing `Nothing` is semantically equivalent to throwing an exception, except we can do this in pure code and without any special support from the runtime system. |
| 2021-07-19 09:00:20 | <dminuoso> | data Maybe a = Nothin | Just a |
| 2021-07-19 09:00:25 | <dminuoso> | instance Monad Maybe where ... |
| 2021-07-19 09:00:42 | <dminuoso> | Voila! You have created exception semantics on your own, no exception primitive support needed in the language. |
| 2021-07-19 09:01:23 | × | Erutuon quits (~Erutuon@user/erutuon) (Ping timeout: 265 seconds) |
| 2021-07-19 09:02:48 | × | lavaman quits (~lavaman@98.38.249.169) (Ping timeout: 252 seconds) |
| 2021-07-19 09:03:00 | <albet70> | can we think it as a failure computation? |
| 2021-07-19 09:03:37 | <albet70> | what about 1/0? |
| 2021-07-19 09:03:47 | <albet70> | 1/0 is an Exception? |
| 2021-07-19 09:04:05 | <albet70> | IO failure is an Exception? |
| 2021-07-19 09:05:09 | <albet70> | fmap (+1) Nothing would be an Exception? |
| 2021-07-19 09:05:30 | <dminuoso> | `Nothing` acts as an exception, yes. |
| 2021-07-19 09:05:55 | <dminuoso> | 1/0 is an interesting subject for several reasons |
| 2021-07-19 09:06:46 | <dminuoso> | % :t (1/0) |
| 2021-07-19 09:06:46 | <yahb> | dminuoso: ; <interactive>:1:3: error: Variable not in scope: (/) :: t0 -> t1 -> t |
| 2021-07-19 09:06:59 | <dminuoso> | % :q |
| 2021-07-19 09:06:59 | <yahb> | dminuoso: |
| 2021-07-19 09:07:00 | <dminuoso> | % :t (1/0) |
| 2021-07-19 09:07:01 | <yahb> | dminuoso: Fractional a => a |
| 2021-07-19 09:07:06 | <dminuoso> | % :i Fractional |
| 2021-07-19 09:07:08 | <yahb> | dminuoso: type Fractional :: * -> Constraint; class Num a => Fractional a where; (/) :: a -> a -> a; recip :: a -> a; fromRational :: Rational -> a; {-# MINIMAL fromRational, (recip | (/)) #-}; -- Defined in `GHC.Real'; instance Fractional a => Fractional (Identity a) -- Defined in `Data.Functor.Identity'; instance forall a k (b :: k). Fractional a => Fractional (Const a b) -- Defined in `Data.Functor.Co |
| 2021-07-19 09:07:19 | <dminuoso> | % :t (/) |
| 2021-07-19 09:07:20 | <yahb> | dminuoso: Fractional a => a -> a -> a |
| 2021-07-19 09:07:34 | <dminuoso> | albet70: ^- so you see, this is either Float or Double, at which point IEEE 754 semantics apply. |
| 2021-07-19 09:08:05 | <dminuoso> | Under which 1/0 is defined to be either positive or negative infinity (depending on the sign of 0) |
All times are in UTC.