Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2020-11-03 13:06:01 <dminuoso> So our use of fromInteger has type `Num _v => Integer _v`
2020-11-03 13:06:04 <dminuoso> err
2020-11-03 13:06:06 <dminuoso> So our use of fromInteger has type `Num _v => Integer -> _v`
2020-11-03 13:06:12 × mmohammadi9812 quits (~mmohammad@188.210.118.100) (Ping timeout: 260 seconds)
2020-11-03 13:06:28 <dminuoso> 14:04:55 dminuoso | so (fromInteger 2) :: _u
2020-11-03 13:06:34 <dminuoso> 14:05:23 dminuoso | So we know that _u = Fix Mex
2020-11-03 13:06:43 <dminuoso> so we have `(fromInteger 2) :: Fix Mex`
2020-11-03 13:06:52 <dminuoso> So we know that `_v = Fix Mex`
2020-11-03 13:07:03 heatsink joins (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net)
2020-11-03 13:07:16 <dminuoso> We're all done now, but we need `Num (Fix Mex)`
2020-11-03 13:07:16 <miladz68> there is no instance for fromInteger 2 :: Fix Mex ?
2020-11-03 13:07:24 <dminuoso> But no such instance exists
2020-11-03 13:07:28 <dminuoso> So GHC bails out
2020-11-03 13:07:45 × alp quits (~alp@2a01:e0a:58b:4920:2923:faed:144a:c0cf) (Ping timeout: 272 seconds)
2020-11-03 13:07:47 × ghghghgh quits (d4fc771c@212.252.119.28) (Remote host closed the connection)
2020-11-03 13:08:20 <dminuoso> miladz68: If you type annotated `2 :: Int` you'd get a better diagnostic. The problem in your case is that numbers are *so* polymorphic, that they keep the type inference going much longer. :)
2020-11-03 13:08:47 <miladz68> dminusoso wow, I actually understand it :). thanks. you saved me a week of frustrations
2020-11-03 13:08:56 <dminuoso> miladz68: Btw, in that above algorithm, if we are left with any "as-of-yet unknown types" at the end, we will just quantify them back!
2020-11-03 13:09:00 mmohammadi9812 joins (~mmohammad@188.210.118.100)
2020-11-03 13:09:06 <dminuoso> for instance if we wrote:
2020-11-03 13:09:39 <dminuoso> `f x = x` we'd say `x :: _u`, so `f :: _u -> _u`, done! Then we generalize back, give the type variable some random name, and then we have `f :: x -> x`
2020-11-03 13:10:02 <dminuoso> miladz68: And that in principle is how type inference in GHC works.
2020-11-03 13:10:07 <dminuoso> Do watch the video! :)
2020-11-03 13:10:56 × ahmr88 quits (~ahmr88@cpc85006-haye22-2-0-cust131.17-4.cable.virginm.net) (Read error: Connection reset by peer)
2020-11-03 13:10:59 <miladz68> dminusoso I wil for sure. I feel much confortable with GHC now. Thanks a lot.
2020-11-03 13:11:02 × Rudd0 quits (~Rudd0@185.189.115.98) (Ping timeout: 272 seconds)
2020-11-03 13:11:52 × heatsink quits (~heatsink@107-136-5-69.lightspeed.sntcca.sbcglobal.net) (Ping timeout: 260 seconds)
2020-11-03 13:12:10 <dminuoso> miladz68: Interesting to note, the consequences of this type inference algorithm, is that GHC can make wrong assumptions about types, sometimes giving unification errors in really strange places.
2020-11-03 13:12:32 CyB3rW0rm parts (~fedora@143.244.38.33) ("Leaving")
2020-11-03 13:12:34 xerox_ joins (~xerox@unaffiliated/xerox)
2020-11-03 13:12:41 ahmr88 joins (~ahmr88@cpc85006-haye22-2-0-cust131.17-4.cable.virginm.net)
2020-11-03 13:12:50 ensyde joins (~ensyde@99-185-235-117.lightspeed.chrlnc.sbcglobal.net)
2020-11-03 13:13:21 <dminuoso> (The consequence is not that it will fail to report on errors, but it can lead GHC to just assume a fact, and then go on and keep applying inference rules with that fact)
2020-11-03 13:13:38 <dminuoso> If it doesnt work out it *will* error out, but not necessarily in the place you expect it to
2020-11-03 13:13:54 <dminuoso> So adding type annotations helps limit how far inference can go
2020-11-03 13:14:05 <dminuoso> (So if you ever have strange type errors you cant figure out, add type annotations/ascriptions!)
2020-11-03 13:14:35 <miladz68> dminusoso like adding ::Int next to 2 in my example
2020-11-03 13:14:40 <dminuoso> Right.
2020-11-03 13:14:50 <miladz68> dminusoso and one more question, did you learn all this by watching that one video ?
2020-11-03 13:14:58 <dminuoso> % t :: Fix Mex; t = Fix (Con 2)
2020-11-03 13:14:59 <yahb> dminuoso: ; <interactive>:36:28: error:; * No instance for (Num (Fix Mex)) arising from the literal `2'; * In the first argument of `Con', namely `2'; In the first argument of `Fix', namely `(Con 2)'; In the expression: Fix (Con 2)
2020-11-03 13:15:02 <dminuoso> % t :: Fix Mex; t = Fix (Con (2 :: Int))
2020-11-03 13:15:03 <yahb> dminuoso: ; <interactive>:37:24: error:; * Couldn't match type `Int' with `Fix Mex'; Expected type: Mex (Fix Mex); Actual type: Mex Int; * In the first argument of `Fix', namely `(Con (2 :: Int))'; In the expression: Fix (Con (2 :: Int)); In an equation for `t': t = Fix (Con (2 :: Int))
2020-11-03 13:15:26 <dminuoso> miladz68: No, just things you pick up :)
2020-11-03 13:15:30 macrover joins (~macrover@ip70-189-231-35.lv.lv.cox.net)
2020-11-03 13:15:36 <dminuoso> And other folks in here who helped explain
2020-11-03 13:15:52 <dminuoso> (Though I did use the video to understand some subtleties of the type inference involving GADTs)
2020-11-03 13:16:54 <miladz68> I will watch the video and try to use my brain more instead of the compiler
2020-11-03 13:17:45 × ensyde quits (~ensyde@99-185-235-117.lightspeed.chrlnc.sbcglobal.net) (Ping timeout: 265 seconds)
2020-11-03 13:18:05 <dminuoso> miladz68: http://dev.stephendiehl.com/fun/006_hindley_milner.html is also a good read
2020-11-03 13:18:24 <dminuoso> And if you want to dive into the theory and formal methods, Pierces Types and Programming Languages is an excellent read
2020-11-03 13:18:44 lucasb joins (uid333435@gateway/web/irccloud.com/x-uaaedzwtlfjjcpgy)
2020-11-03 13:21:00 <merijn> miladz68: Honestly, just doing type inference by hand on a piece of paper helps tons
2020-11-03 13:21:16 <miladz68> dminusoso I will check them out both. I think I will checkout the book first. probably will more than a few months for someone without much background is CS theory
2020-11-03 13:21:52 <dminuoso> As a cute excercise:
2020-11-03 13:21:57 <dminuoso> % :t id
2020-11-03 13:21:58 <yahb> dminuoso: a -> a
2020-11-03 13:22:01 <dminuoso> % :t flip id
2020-11-03 13:22:01 <yahb> dminuoso: b -> (b -> c) -> c
2020-11-03 13:22:04 <dminuoso> % :t flip
2020-11-03 13:22:04 <yahb> dminuoso: (a -> b -> c) -> b -> a -> c
2020-11-03 13:22:14 <dminuoso> Figure out why `flip id` has the type it has! :)
2020-11-03 13:22:39 <miladz68> merjin thank sounds exactly like what I would be interested in but I need to see examples of how it is done
2020-11-03 13:24:56 <miladz68> dminusoso I can't believe that example you just mentioned. why is it so ? ok don't tell me. let me think
2020-11-03 13:26:03 <merijn> miladz68: It helps to rename the type variables of id and 'flip' so they are unique and then just working out the equations
2020-11-03 13:26:22 geekosaur joins (82659a09@host154-009.vpn.uakron.edu)
2020-11-03 13:26:34 <dminuoso> merijn: Start like I did. Swap out type variables for "as-of-yet unknown types", perhaps start them with an underscore like I did?
2020-11-03 13:26:50 <dminuoso> Write it down on paper or an editor :)
2020-11-03 13:29:37 × piyush-kurur quits (~user@14.139.174.50) (Ping timeout: 264 seconds)
2020-11-03 13:30:55 × cfricke quits (~cfricke@unaffiliated/cfricke) (Quit: WeeChat 2.9)
2020-11-03 13:31:14 × p-core quits (~Thunderbi@193.165.236.104) (Ping timeout: 264 seconds)
2020-11-03 13:33:35 revtintin joins (~revtintin@158.140.144.34)
2020-11-03 13:35:40 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Quit: leaving)
2020-11-03 13:35:50 × jonatanb quits (~jonatanb@83.24.9.26.ipv4.supernova.orange.pl) (Quit: Leaving...)
2020-11-03 13:38:04 nbloomf joins (~nbloomf@2600:1700:ad14:3020:2543:65c:876:3dae)
2020-11-03 13:39:16 × jonathanx quits (~jonathan@dyn-8-sc.cdg.chalmers.se) (Remote host closed the connection)
2020-11-03 13:40:15 × britva quits (~britva@2a02:aa13:7240:2980:292a:d07d:3ab9:26ba) (Quit: This computer has gone to sleep)
2020-11-03 13:42:24 britva joins (~britva@31-10-157-156.cgn.dynamic.upc.ch)
2020-11-03 13:44:35 thir joins (~thir@p200300f27f0b7e00f4e9381c2bf90854.dip0.t-ipconnect.de)
2020-11-03 13:47:02 privalovy_lekvar is now known as hexic
2020-11-03 13:48:28 × drbean quits (~drbean@TC210-63-209-173.static.apol.com.tw) (Ping timeout: 260 seconds)
2020-11-03 13:49:33 × thir quits (~thir@p200300f27f0b7e00f4e9381c2bf90854.dip0.t-ipconnect.de) (Ping timeout: 268 seconds)
2020-11-03 13:54:00 machinedgod joins (~machinedg@207.253.244.210)
2020-11-03 13:57:02 × nbloomf quits (~nbloomf@2600:1700:ad14:3020:2543:65c:876:3dae) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2020-11-03 13:57:38 nbloomf joins (~nbloomf@2600:1700:ad14:3020:2543:65c:876:3dae)
2020-11-03 13:58:03 Ranhir joins (~Ranhir@157.97.53.139)
2020-11-03 13:58:24 × acidjnk_new2 quits (~acidjnk@p200300d0c718f623ecaa4caf6803be45.dip0.t-ipconnect.de) (Ping timeout: 240 seconds)
2020-11-03 13:59:33 × ubert quits (~Thunderbi@2a02:8109:9880:303c:ca5b:76ff:fe29:f233) (Remote host closed the connection)
2020-11-03 13:59:44 ubert joins (~Thunderbi@2a02:8109:9880:303c:e6b3:18ff:fe83:8f33)
2020-11-03 14:00:34 × nbloomf quits (~nbloomf@2600:1700:ad14:3020:2543:65c:876:3dae) (Client Quit)
2020-11-03 14:03:43 hyperisco joins (~hyperisco@d192-186-117-226.static.comm.cgocable.net)
2020-11-03 14:05:28 jonathanx joins (~jonathan@dyn-8-sc.cdg.chalmers.se)
2020-11-03 14:08:54 avdb joins (~avdb@ip-83-134-109-138.dsl.scarlet.be)
2020-11-03 14:11:01 × thunderrd quits (~thunderrd@183.182.115.112) (Remote host closed the connection)
2020-11-03 14:11:38 daydaynatation joins (~user@roc37-h01-176-170-197-243.dsl.sta.abo.bbox.fr)
2020-11-03 14:11:44 × bitmapper quits (uid464869@gateway/web/irccloud.com/x-xutwnldhztnzggtn) (Quit: Connection closed for inactivity)
2020-11-03 14:12:07 × xff0x quits (~fox@2001:1a81:53b4:ba00:5006:d65a:90eb:4407) (Ping timeout: 260 seconds)
2020-11-03 14:12:15 <daydaynatation> I have installed the array package, yet when i try to load it into ghci, it still says it's in a hidden package
2020-11-03 14:12:21 ggole joins (~ggole@2001:8003:8119:7200:4c8:75c2:97ad:422b)
2020-11-03 14:12:34 <daydaynatation> import Data.Array

All times are in UTC.