JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  March 2016

COMP-FORTRAN-90 March 2016

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: What are the possible hurdles to enhanced "enum" functionality in Fortran?

From:

Bill Long <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Thu, 24 Mar 2016 13:04:53 +0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (308 lines)

On Mar 24, 2016, at 7:35 AM, Tom Clune <[log in to unmask]> wrote:

> 
>> On Mar 23, 2016, at 10:24 PM, Vipul Parekh <[log in to unmask]> wrote:
>> 
>> Thank you for your response and your prior proposal effort.  It received 4 "like"s, 1 "love" but 6 dislikes (at least no hate!), if I understood correctly.  Considering the year of the proposal, you might have been way ahead of where Fortranners were that stage of language evolution and perhaps there was post-Fortran 2003 fatigue too!  I wonder if there might be better reception now, given better understanding and appreciation of modern programming idioms and paradigm, particularly with OO, among many in the Fortran community  Of course, from what I gather, the committee won't be considering any new proposals until the current revision (2015?) is all done.
> 
> Correct.   And then the challenge will be to narrow priorities.  As much as we on the applications side want many new features, it does us no good if we dump too much on the vendors.   So the goal is to also estimate the implementation difficulty as we propose/prioritize features for 2020.  


Right.  And, it is perhaps mentioning that any change that affects the typing system (apart from trivial syntax enhancements like type(integer)) can involve non-trivial implementation issues. 

Cheers,
Bill


> The president of the committee has indicated that the process will rely heavily on _use cases_.   I.e.  the proposer will need to explain likely/relevant scenarios for which the new feature significantly improves the implementation.     
> 
>> 
>> It's reassuring to read, '"There would be no conflicts with the standard to introduce enumeration types.  If they were introduced, they would not invalidate any program that conforms to current standards."
>> 
>> Your point, "My later thoughts on the topic is that enumeration types ought to be extensible," makes sense.
>> 
>> If you were to develop again your proposal now, to what extent you think it will support the couple of examples I show in my first e-mail?
> 
> As I’m relatively new to the committee, I’ll await Van’s response and others to this.
> 
> Cheers,
> 
> - Tom
> 
>> 
>> Regards,
>> Vipul
>> 
>> On Wed, Mar 23, 2016 at 7:32 PM, Van Snyder <[log in to unmask]> wrote:
>> I proposed this in 2004.  See paper http://j3-fortran.org/doc/year/04/04-139r1.ps.  It met with an unwelcome reception, as can be seen in http://j3-fortran.org/doc/year/04/04-302.xls.  There would be no conflicts with the standard to introduce enumeration types.  If they were introduced, they would not invalidate any program that conforms to current standards.  My later thoughts on the topic is that enumeration types ought to be extensible.
>> 
>> In Ada, function results participate in generic resolution, and enumerators are considered to be zero-argument functions.  It is therefore possible to have enumerators of different types with the same names.  Proposals to include function result types (and kinds, and ranks) in generic resolution have also met with unwelcome receptions.
>> 
>> On Wed, 2016-03-23 at 16:52 -0400, Vipul Parekh wrote:
>>> Hi,
>>> 
>>> 
>>> I posted this on comp.lang.fortran, but not sure how many of you read that newsgroup.  I apologize for any duplication of effort.
>>> 
>>> 
>>> Regards,
>>> Vipul Parekh
>>> 
>>> 
>>> ---------------------------------------------------
>>> From a language and compiler development point-of-view, putting aside any time/resource constraints, are there any fundamental issues with including an improved "enum" functionality in Fortran? 
>>> 
>>> That is, from the language aspects of Fortran syntax, semantics, and taxonomy, is there an intrinsic problem that might preclude any enhancements beyond the facility for enum introduced in Fortran starting with the 2003 revision toward standard interoperability with C? 
>>> 
>>> I would greatly appreciate any knowledgeable feedback on above. 
>>> 
>>> I'm greatly interested in better support for "enum" types in Fortran.  I would like to adopt many of the so-called "good coding practices" involving enum that are used regularly by my peer group within industry in languages such as C++, Python, Java, and Microsoft .NET.  Listed below are a couple of examples in C++ that capture most of what I would like to do. 
>>> 
>>> 1.  Intrinsic support for an integral type of "enum" which provides facilities toward improved code readability and some form of type safety.  You will see in C++, I can do the following for working with days in a week: 
>>> 
>>> --- begin code --- 
>>> #include <iostream> 
>>> using namespace std; 
>>> 
>>> enum Days { Sunday = 0, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; 
>>> 
>>> // main example 
>>> int main(void) 
>>> { 
>>> 
>>>    Days Today; 
>>>    Today = Days::Wednesday; // Ok, and code reads much better too 
>>>    //Today = 2;             // Error, cannot convert from int to Days 
>>> 
>>>    switch ( Today ) 
>>>    { 
>>>       case Days::Wednesday: 
>>>          cout << "It's a Wednesday" << endl; 
>>>          break; 
>>>       case Days::Saturday: 
>>>       case Days::Sunday: 
>>>          cout << "It's a Weekend!" << endl; 
>>>          break; 
>>>       default: cout << "It's some other day." << endl; 
>>>    } 
>>> 
>>>    return 0; 
>>> 
>>> } 
>>> --- end code --- 
>>> 
>>> It will be nice if I can do in Fortran: 
>>> --- begin pseudo code --- 
>>> module m 
>>>    implicit none 
>>>    private 
>>>    enum, public :: Days  !.. Not supported at present 
>>>       enumerator :: Sunday = 0 
>>>       enumerator :: Monday 
>>>       enumerator :: Tuesday 
>>>       enumerator :: Wednesday 
>>>       enumerator :: Thursday 
>>>       enumerator :: Friday 
>>>       enumerator :: Saturday 
>>>    end enum 
>>> end module m 
>>> program p 
>>>    use m, only : Days 
>>>    type(Days) :: Today 
>>>    Today = Days%Tuesday 
>>>    !Today = 2  !! Should not be allowed, no direct integer assignment to enum type 
>>>    select case ( Today ) 
>>>       case ( Days%Tuesday ) 
>>>          print *, "It's a Tuesday!" 
>>>       case ( Days%Saturday, Days%Sunday ) 
>>>          print *, "It's a weekend!" 
>>>       case default 
>>>          print *, "It's some other day!" 
>>>    end select 
>>>    stop 
>>> end program p 
>>> --- end pseudo code --- 
>>> 
>>> Does anyone of you think facilities along the above lines are simply inconsistent with the language?  If so, why?  Note I'm not wedded to my invented syntax in the above pseudo snippet; it was just for illustration purposes.  My interest is really in being to program in "modern" Fortran the kind of coding idioms involving "enum" that my peers have accepted as more readable and type-safe. 
>>> 
>>> 2.  Better support for use of "enum" with object-oriented (OO) design.  I would like to build on the above point and extend it to components for derived types so it can help me further in OO concepts involving class design, data packaging, information hiding, and so forth.  Consider an example in C++ again where one can write a class for day of a week as follows: 
>>> 
>>> --- begin code snippet --- 
>>> #include <iostream> 
>>> using namespace std; 
>>> 
>>> class Day 
>>> { 
>>> public: 
>>> 
>>>    enum Days { Sunday = 0, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, InvalidDay }; 
>>> 
>>>    // Constructors 
>>>    Day(void); 
>>>    Day(Days d); 
>>> 
>>>    // Overloaded assignment operator 
>>>    Day& operator = (Days d); 
>>> 
>>>    // Overloaded comparison operator 
>>>    bool operator== (const Days d) const; 
>>> 
>>>    // Accessor function 
>>>    Days getDay(void) const; 
>>> 
>>> private: 
>>> 
>>>    // Data member 
>>>    Days m_day; 
>>> }; 
>>> 
>>> Day::Days Day::getDay(void) const 
>>> { 
>>>    return m_day; 
>>> } 
>>> 
>>> // Constructors 
>>> Day::Day(void) : m_day(Sunday) {} 
>>> 
>>> Day::Day(Days _d) : m_day(_d) {} 
>>> 
>>> // Assignment operator 
>>> Day& Day::operator= (Days _d) 
>>> { 
>>>    m_day = _d; 
>>>    return *this; 
>>> } 
>>> 
>>> // Comparison operator 
>>> bool Day::operator== (const Days _d) const 
>>> { 
>>>    return (m_day == _d); 
>>> } 
>>> 
>>> // main example 
>>> int main(void) 
>>> { 
>>> 
>>>    Day Today; 
>>> 
>>>    Today = Day::Tuesday;  // Ok, and code reads much better too 
>>>    //Today = 2;           // Error, cannot convert from int to Days 
>>> 
>>>    switch ( Today.getDay() ) 
>>>    { 
>>>       case Day::Tuesday: 
>>>          cout << "It's a Tuesday" << endl; 
>>>          break; 
>>>       case Day::Saturday: 
>>>       case Day::Sunday: 
>>>          cout << "It's a Weekend!" << endl; 
>>>          break; 
>>>       default: cout << "It's some other day." << endl; 
>>>    } 
>>> 
>>>    return 0; 
>>> } 
>>> --- end code snippet --- 
>>> 
>>> So I would like to be able to do in Fortran, 
>>> 
>>> --- begin pseudo code snippet --- 
>>> module m 
>>>    implicit none 
>>>    private 
>>>    type, public :: Day 
>>>       private 
>>>       enum, public :: Days    !  Note how enum is "bound" to the type! 
>>>          enumerator :: Sunday = 0 
>>>          enumerator :: Monday 
>>>          enumerator :: Tuesday 
>>>          enumerator :: Wednesday 
>>>          enumerator :: Thursday 
>>>          enumerator :: Friday 
>>>          enumerator :: Saturday 
>>>       end enum 
>>>       type(Days) :: m_day 
>>>    contains 
>>>       private 
>>>       procedure, pass(this) :: assign_day 
>>>       procedure, pass(this), public :: getDay 
>>>       generic, public :: assignment(=) => assign_day 
>>>    end type 
>>> 
>>> contains 
>>>    subroutine assign_day( this, SomeDay ) 
>>>       !.. Argument list 
>>>       class(Day), intent(inout) :: this 
>>>       type(Days), intent(in)    :: SomeDay 
>>> 
>>>       this%m_day = SomeDay 
>>> 
>>>    end function assign_day 
>>> 
>>>    function getDay( this ) result( ThisDay ) 
>>>       !.. Argument list 
>>>       class(Day), intent(in) :: this 
>>>       !.. Function result 
>>>       type(Days) :: ThisDay 
>>> 
>>>       ThisDay = this%m_day 
>>> 
>>>    end function getDay 
>>> 
>>> end module m 
>>> 
>>> program p 
>>>    use m, only : Day  !.. Note the compact use statement 
>>>    type(Day) :: Today 
>>>    Today = Day%Tuesday 
>>>    select case ( Today%getDay() ) 
>>>       case ( Day%Tuesday ) 
>>>          print *, "It's a Tuesday!" 
>>>       case ( Day%Saturday, Day%Sunday ) 
>>>          print *, "It's a weekend!" 
>>>       case default 
>>>          print *, "It's some other day!" 
>>>    end select 
>>>    stop 
>>> end program p 
>>> --- end pseudo code snippet --- 
>>> 
>>> Again, are there any basic language and compiler development constraints that would prevent a future Fortran standard revision (Fortran 20XY beyond the one in progress Fortran 2015) from adopting support along the above lines?  Note I am not asking about the time and effort it takes in getting any such change discussed and accepted by the standards committee and then to get it all documented in standard-speak and for compiler writers to get the features implemented. 
>>>   
>>> Also, note I am not here to debate in general any of the limitations with using enum types in programming (I understand the pros and cons).  Nor do I want to know any of the "virtues" of writing so-called simple, concise code with FORTRAN; I've supported many such programs and I know what they entail. 
>>> 
>>> Instead I have a general interest in understanding better the hurdles that might hinder further evolution of the Fortran language and presently I'm pondering over the enum functionality.  Is it mainly time and resource constraints?  Or is there more to it than meets the eye? 
>>> 
>>> Fortran 2003 introduced "ENUM, BIND(C)" keyword to encapsulate enumerators for interoperability with C and Fortran 2008 brought the TYPE statement for intrinsic types.  In my simple-minded thinking, I see these as seeds that can grow into better support for enum.  Since an "enum" type is a particular packaging of an integral type and the elements to do such packaging appear to be present in Fortran, I wonder if Fortran language can be extended to provide more "syntactic sugar" for coders. 
>>> 
>>> Thank you for your attention, 
>>> 
>> 
>> 
> 
> Thomas Clune, Ph. D. 	<[log in to unmask]>
> Software Infrastructure Team Lead
> Global Modeling and Assimilation Office, Code 610.1
> NASA GSFC		
> MS 610.1 B33-C128
> Greenbelt, MD 20771
> 301-286-4635
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

Bill Long                                                                       [log in to unmask]
Fortran Technical Support  &                                  voice:  651-605-9024
Bioinformatics Software Development                     fax:  651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

December 2023
February 2023
November 2022
September 2022
February 2022
January 2022
June 2021
November 2020
September 2020
June 2020
May 2020
April 2020
December 2019
October 2019
September 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager