tag:blogger.com,1999:blog-7094652.post471843912243762118..comments2024-03-13T10:20:27.668+00:00Comments on Neil Mitchell's Blog (Haskell etc): Reviewing View PatternsNeil Mitchellhttp://www.blogger.com/profile/13084722756124486154noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-7094652.post-83570965864955961922014-07-16T19:39:42.988+01:002014-07-16T19:39:42.988+01:00Anon: No, Data.View never got created. There are n...Anon: No, Data.View never got created. There are no "free" view patterns without a function first. I now consider that a good thing, a general Data.View doesn't seem useful enough to be justified.Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-5106636244879927322014-07-16T11:18:40.951+01:002014-07-16T11:18:40.951+01:00This post is already a little old, but: I've n...This post is already a little old, but: I've never seen Data.View.view? Do we have that somewhere?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-80638401158205630932010-01-07T15:33:21.137+00:002010-01-07T15:33:21.137+00:00True story: I was writing bindings to a C library ...True story: I was writing bindings to a C library and I had some code like this:<br /><br />> do<br />> ...<br />> let Blah n x y = ...<br />> ...<br /><br />when the compiler informed me that n was a CInt but I was using it later as an Int.<br /><br />"No problem," I thought, "I'll just use a view pattern (Blah (fromIntegral -> n) x y), like I learned from Neil's blog post."<br /><br />"But then, this is library code. Do I really want a dependency on that language feature? And there's that annoying warning in GHC 6.10..."<br /><br />And so I promptly wrote<br /><br />> do<br />> ...<br />> let Blah n0 x y = ...<br />> n = fromIntegral n<br />> ...<br /><br />(sigh)Unknownhttps://www.blogger.com/profile/13542319951893024109noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-78952874424129455522009-11-23T21:19:46.792+00:002009-11-23T21:19:46.792+00:00Christophe: Indeed I did, I was adapting from an e...Christophe: Indeed I did, I was adapting from an example in terms of f/g trying to make it more meaningful, and added a typo. Now fixed.Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-68470950766844693242009-11-23T21:16:32.365+00:002009-11-23T21:16:32.365+00:00Small comment:
f v_1 | case v_2 of _:_ -> True ...Small comment:<br />f v_1 | case v_2 of _:_ -> True ; _ -> False = ...<br /> where v_2 = f v_1 ; min:ascending = v_2<br /><br />You probably mean 'where v_2 = sort v_1'.Christophe Poucethttps://www.blogger.com/profile/02320035941417593372noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-24362860276055861662009-11-23T11:56:23.172+00:002009-11-23T11:56:23.172+00:00Dan - thanks for implementing the feature in the f...Dan - thanks for implementing the feature in the first place, my comments on your comments are:<br /><br />1) I want my compiler warnings to be complete - otherwise they are impossible to shut up.<br /><br />2) Yes, the scoping is trick, but I'm sure it could be done.<br /><br />Martijn: 1 in Haskell means Prelude.fromInteger 1, there are loads of places where functions are implicitly inserted. I think I probably agree with you though that it should be a predefined name, rather than the name in scope.Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-49452044897336323072009-11-21T15:50:26.611+00:002009-11-21T15:50:26.611+00:00I understand that (-> pat) would be convenient ...I understand that (-> pat) would be convenient but I don't like the implicit use of a bound name. It feels very unlike Haskell: nowhere else in the language are names used implicitly.Martijnhttps://www.blogger.com/profile/03420202886083056827noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-10096543493963880502009-11-17T15:11:53.439+00:002009-11-17T15:11:53.439+00:00Glad to hear that view patterns are getting some u...Glad to hear that view patterns are getting some use!<br /><br />Regarding the suggestions:<br /><br />1) The warnings were ridiculous because we thought were were going to rewrite the exhaustiveness checker, but then that never happened. I guess it has been taken care of now, though I wonder what they did: do you want your compiler warnings to be sound (if there's a potential overlap, you get a warning), complete (if there is a warning, then there is definitely an overlap), or neither?<br /><br />2) One tricky thing is that the viewed variables could also appear in the RHS of the 'where' binding, and what do you do with:<br /><br />apply (f -> y) = e where f = y<br /><br />?<br /><br />The translation as <br /><br />apply x = <br />(case f x of y -> e) <br />where f = y <br /><br />doesn't make sense.<br /><br />3) We thought about this but never did it, mostly because we couldn't make up our minds about the fundeps on the view class. If people get some experience and decide what the fundeps should be, it would be easy to implement.Dan Licatahttps://www.blogger.com/profile/05419342217317164459noreply@blogger.com