[GHC] #14812: Dot-Notation for Flipped Function Application
GHC
ghc-devs at haskell.org
Fri Feb 16 09:34:33 UTC 2018
#14812: Dot-Notation for Flipped Function Application
-------------------------------------+-------------------------------------
Reporter: tepan | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Description changed by tepan:
Old description:
> Please allow to put a dot `.` (without spaces) between two things for
> ''flipped'' function application. This could make for code in pseudo-OOP
> style:
>
> {{{#!hs
> encrypt(str) = do {
> str.map(succ);
> }
> }}}
>
> Currently, as a workaround, this can be achieved by defining `(.) = flip
> ($)` (making `.` for function composition unavailable, though):
>
> {{{#!hs
> encrypt(str) = do {
> str.map(succ);
> } where (.) = flip ($)
> }}}
>
> (For a remotely similar look-and-feel, one could use
> `Data.Function.((&))` instead of `(.)`.)
>
> Please note that `.` without spaces is already an OOP-like notational
> convenience in order to denote Modules and their elements.
>
> {{{#!hs
> x = do {
> Prelude.length("Hello World!");
> }
> }}}
>
> This means, that a distinction between ` . ` (with spaces) and `.`
> (without spaces) is already been made, which is why `Just . Just $ 42`
> compiles, wheras `Just.Just $ 42` doesn't. Analogously, with this Feature
> Request implemented, `"Hello".map(succ)` would compile whereas `"Hello" .
> map(succ)"` wouldn't.
New description:
Please allow to put a dot `.` (without whitespaces) between two things for
''flipped'' function application. This could make for code in pseudo-OOP
style:
{{{#!hs
encrypt(str) = do {
str.map(succ);
}
}}}
Currently, as a workaround, this can be achieved by defining `(.) = flip
($)` (making `.` for function composition unavailable, though):
{{{#!hs
encrypt(str) = do {
str.map(succ);
} where (.) = flip ($)
}}}
(For a remotely similar look-and-feel, one could use `Data.Function.((&))`
instead of `(.)`.)
Side note: `.` without whitespaces is already an OOP-like notational
convenience in order to denote Modules and their elements in Haskell.
OOP:
* `Prelude.length("Hello")` (static function `length` of class `Prelude`
applied to `"Hello"`)
Haskell:
* `Prelude.length("Hello")` (function `length` of module `Prelude` applied
to `"Hello"`)
This means, that a distinction between ` . ` (with whitespaces) and `.`
(without whitespaces) is already been made, which is why `Just . Just $
42` compiles, whereas `Just.Just $ 42` doesn't. Analogously, with this
Feature Request implemented, `"Hello".map(succ)` would compile whereas
`"Hello" . map(succ)"` wouldn't.
Current dot-notation for modules (not to be changed):
* `Foo.bar` (`bar` of module `Foo`)
Proposed dot-noation for function application:
* `foo.bar` (function `bar` applied to `foo`)
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14812#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list