Re: DoAndIfThenElse
I've filed https://ghc.haskell.org/trac/ghc/ticket/14842 for it. On 09/02/2018 10.24, Simon Peyton Jones via ghc-devs wrote: > At very least the extension should be documented! Would you like to open > a ticket for that? And even offer a patch? ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
RE: DoAndIfThenElse
I also recall that Idris and Elm have some do-syntax like this: do { x <- e1 ; Just y <- e2 | Nothing -> exceptional-code ; etc ; etc } That is, e2 :: blah -> IO (Maybe t), we can pattern match on the expected Just case, but still provide code for the Nothing case. That’s much better than do { x <- e1 ; mb_y <- e2 ; case mb_y of Nothing -> exceptional-code Just y -> do { etc etc } } I’d love this for Haskell, if someone felt like making a proposal. I do this kind of thing all the time! Simon From: ghc-devs [mailto:ghc-devs-boun...@haskell.org] On Behalf Of Harendra Kumar Sent: 09 February 2018 02:43 To: Brandon Allbery <allber...@gmail.com> Cc: ghc-devs@haskell.org Devs <ghc-devs@haskell.org> Subject: Re: DoAndIfThenElse Since I started programming in Haskell a few years ago I have been using if-then-else in that manner without indentation and I never knew about this extension. I thought this is how it works. It seems this is the default now. But, I remember encountering an error in an older compiler version once and then I figured the my style was accepted in newer compiler versions only. -harendra On 9 February 2018 at 08:08, Brandon Allbery <allber...@gmail.com<mailto:allber...@gmail.com>> wrote: Huh. I wonder if a section went missing; seems like none of the extensions that alter or relax layout are documented currently. (AlternativeLayoutRule, AlternativeLayoutRuleTransitional, DoAndIfThenElse, NondecreasingIndentation, RelaxedLayout) IIRC DoAndIfThenElse relaxes a condition implied by layout but that normally only matters in "do": that if you break it into multiple lines, the "then" and "else" must be indented farther than the "if" or layout will consider them distinct new expressions (and thereby syntax errors). On Thu, Feb 8, 2018 at 9:24 PM, Harendra Kumar <harendra.ku...@gmail.com<mailto:harendra.ku...@gmail.com>> wrote: Hi, I recently found a mention of DoAndIfThenElse extension somewhere. I looked inside the ghc user guide and could not find any such extension. Then I looked in the ghc man page, no mention. I googled and found a very sparse references to it here and there. Then I tried using the extension with ghc and ghc seems to accept it. What's the story behind this, why is it not documented but accepted? thanks, harendra ___ ghc-devs mailing list ghc-devs@haskell.org<mailto:ghc-devs@haskell.org> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs=04%7C01%7Csimonpj%40microsoft.com%7Ceea21f8f64dd4051b39308d56f670635%7Cee3303d7fb734b0c8589bcd847f1c277%7C1%7C0%7C636537410654890985%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1=sT%2F1YhbHklg1rHjqohBwUFyHaIk883E11%2F2%2FRzWx1xA%3D=0> -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com<mailto:allber...@gmail.com> ballb...@sinenomine.net<mailto:ballb...@sinenomine.net> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsinenomine.net=04%7C01%7Csimonpj%40microsoft.com%7Ceea21f8f64dd4051b39308d56f670635%7Cee3303d7fb734b0c8589bcd847f1c277%7C1%7C0%7C636537410654890985%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1=y0Yyny6wJfV47xbvLjyZFhyZoOWRBY4KQNJ3fwhaIZ8%3D=0> ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
RE: DoAndIfThenElse
At very least the extension should be documented! Would you like to open a ticket for that? And even offer a patch? Thanks for pointing this out. Simon From: ghc-devs [mailto:ghc-devs-boun...@haskell.org] On Behalf Of Harendra Kumar Sent: 09 February 2018 02:43 To: Brandon Allbery <allber...@gmail.com> Cc: ghc-devs@haskell.org Devs <ghc-devs@haskell.org> Subject: Re: DoAndIfThenElse Since I started programming in Haskell a few years ago I have been using if-then-else in that manner without indentation and I never knew about this extension. I thought this is how it works. It seems this is the default now. But, I remember encountering an error in an older compiler version once and then I figured the my style was accepted in newer compiler versions only. -harendra On 9 February 2018 at 08:08, Brandon Allbery <allber...@gmail.com<mailto:allber...@gmail.com>> wrote: Huh. I wonder if a section went missing; seems like none of the extensions that alter or relax layout are documented currently. (AlternativeLayoutRule, AlternativeLayoutRuleTransitional, DoAndIfThenElse, NondecreasingIndentation, RelaxedLayout) IIRC DoAndIfThenElse relaxes a condition implied by layout but that normally only matters in "do": that if you break it into multiple lines, the "then" and "else" must be indented farther than the "if" or layout will consider them distinct new expressions (and thereby syntax errors). On Thu, Feb 8, 2018 at 9:24 PM, Harendra Kumar <harendra.ku...@gmail.com<mailto:harendra.ku...@gmail.com>> wrote: Hi, I recently found a mention of DoAndIfThenElse extension somewhere. I looked inside the ghc user guide and could not find any such extension. Then I looked in the ghc man page, no mention. I googled and found a very sparse references to it here and there. Then I tried using the extension with ghc and ghc seems to accept it. What's the story behind this, why is it not documented but accepted? thanks, harendra ___ ghc-devs mailing list ghc-devs@haskell.org<mailto:ghc-devs@haskell.org> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs=04%7C01%7Csimonpj%40microsoft.com%7Ceea21f8f64dd4051b39308d56f670635%7Cee3303d7fb734b0c8589bcd847f1c277%7C1%7C0%7C636537410654890985%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1=sT%2F1YhbHklg1rHjqohBwUFyHaIk883E11%2F2%2FRzWx1xA%3D=0> -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com<mailto:allber...@gmail.com> ballb...@sinenomine.net<mailto:ballb...@sinenomine.net> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsinenomine.net=04%7C01%7Csimonpj%40microsoft.com%7Ceea21f8f64dd4051b39308d56f670635%7Cee3303d7fb734b0c8589bcd847f1c277%7C1%7C0%7C636537410654890985%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1=y0Yyny6wJfV47xbvLjyZFhyZoOWRBY4KQNJ3fwhaIZ8%3D=0> ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Re: DoAndIfThenElse
Since I started programming in Haskell a few years ago I have been using if-then-else in that manner without indentation and I never knew about this extension. I thought this is how it works. It seems this is the default now. But, I remember encountering an error in an older compiler version once and then I figured the my style was accepted in newer compiler versions only. -harendra On 9 February 2018 at 08:08, Brandon Allberywrote: > Huh. I wonder if a section went missing; seems like none of the extensions > that alter or relax layout are documented currently. > (AlternativeLayoutRule, AlternativeLayoutRuleTransitional, > DoAndIfThenElse, NondecreasingIndentation, RelaxedLayout) > > IIRC DoAndIfThenElse relaxes a condition implied by layout but that > normally only matters in "do": that if you break it into multiple lines, > the "then" and "else" must be indented farther than the "if" or layout will > consider them distinct new expressions (and thereby syntax errors). > > On Thu, Feb 8, 2018 at 9:24 PM, Harendra Kumar > wrote: > >> Hi, >> >> I recently found a mention of DoAndIfThenElse extension somewhere. I >> looked inside the ghc user guide and could not find any such extension. >> Then I looked in the ghc man page, no mention. I googled and found a very >> sparse references to it here and there. Then I tried using the extension >> with ghc and ghc seems to accept it. What's the story behind this, why is >> it not documented but accepted? >> >> thanks, >> harendra >> >> ___ >> ghc-devs mailing list >> ghc-devs@haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs >> >> > > > -- > brandon s allbery kf8nh sine nomine > associates > allber...@gmail.com > ballb...@sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Re: DoAndIfThenElse
Hi, not sure if this helps. testsuite/tests/parser/should_compile/DoAndIfThenElse.hs gives us ``` {-# LANGUAGE DoAndIfThenElse #-} module DoAndIfThenElse where foo :: IO () foo = do if True then return () else return () ``` and there is some other mention in libraries/bytestring/bench/wiki-haskell.html, which states: ``` Haskell 2010 adds the foreign function interface (FFI) to Haskell, allowing for bindings to other programming languages, fixes some syntax issues (changes in the formal grammar) and bans so-called "n-plus-k-patterns", that is, definitions of the form fact (n+1) = (n+1) * fact n are no longer allowed. It introduces the Language-Pragma-Syntax-Extension which allows for designating a Haskell source as Haskell 2010 or requiring certain extensions to the Haskell language. The names of the extensions introduced in Haskell 2010 are DoAndIfThenElse, HierarchicalModules, EmptyDataDeclarations, FixityResolution, ForeignFunctionInterface, LineCommentSyntax, PatternGuards, RelaxedDependencyAnalysis, LanguagePragma and NoNPlusKPatterns.[1] ``` in compiler/main/DynFlags.hs we find ``` languageExtensions (Just Haskell2010) = [LangExt.ImplicitPrelude, LangExt.MonomorphismRestriction, LangExt.DatatypeContexts, LangExt.TraditionalRecordSyntax, LangExt.EmptyDataDecls, LangExt.ForeignFunctionInterface, LangExt.PatternGuards, LangExt.DoAndIfThenElse, LangExt.RelaxedPolyRec] ``` So, in Haskell2010, it's always on, and allows to write the above code. When we set NoDoAndIfThenElse, we get ``` Unexpected semi-colons in conditional: if True; then return (); else return () Perhaps you meant to use DoAndIfThenElse? ``` And then there's https://prime.haskell.org/wiki/DoAndIfThenElse. Cheers, Moritz > On Feb 9, 2018, at 10:24 AM, Harendra Kumarwrote: > > Hi, > > I recently found a mention of DoAndIfThenElse extension somewhere. I looked > inside the ghc user guide and could not find any such extension. Then I > looked in the ghc man page, no mention. I googled and found a very sparse > references to it here and there. Then I tried using the extension with ghc > and ghc seems to accept it. What's the story behind this, why is it not > documented but accepted? > > thanks, > harendra > ___ > ghc-devs mailing list > ghc-devs@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Re: DoAndIfThenElse
Huh. I wonder if a section went missing; seems like none of the extensions that alter or relax layout are documented currently. (AlternativeLayoutRule, AlternativeLayoutRuleTransitional, DoAndIfThenElse, NondecreasingIndentation, RelaxedLayout) IIRC DoAndIfThenElse relaxes a condition implied by layout but that normally only matters in "do": that if you break it into multiple lines, the "then" and "else" must be indented farther than the "if" or layout will consider them distinct new expressions (and thereby syntax errors). On Thu, Feb 8, 2018 at 9:24 PM, Harendra Kumarwrote: > Hi, > > I recently found a mention of DoAndIfThenElse extension somewhere. I > looked inside the ghc user guide and could not find any such extension. > Then I looked in the ghc man page, no mention. I googled and found a very > sparse references to it here and there. Then I tried using the extension > with ghc and ghc seems to accept it. What's the story behind this, why is > it not documented but accepted? > > thanks, > harendra > > ___ > ghc-devs mailing list > ghc-devs@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs > > -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs