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  October 2016

COMP-FORTRAN-90 October 2016

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: Enhanced SELECT CASE, derived type that extend from some INTRINSIC ABSTRACT type and all that

From:

Van Snyder <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Mon, 31 Oct 2016 15:13:26 -0700

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (389 lines)

Tom:

Take a look at 04-139r1.

Van

On Wed, 2016-10-26 at 17:24 +0000, Clune, Thomas L. (GSFC-6101) wrote:
> Hi Vipul, 
> 
> 
> I think there is a compelling case for better ENUMs, but of course
> will defer on where they would be in terms of priorities.  And I
> certainly cannot comment on the implementation difficulty - a very
> important factor in the committee’s decision-making process.
> 
> 
> Presumably _if_ there were an enhanced form of ENUM, then an
> appropriate extension to SELECT CASE would be considered as part of
> the process of integrating the new feature consistently into the
> standard.
> 
> 
> Cheers,
> 
> 
> - Tom
> 
> 
> 
> 
> 
> 
> 
> > On Oct 26, 2016, at 12:31 PM, Vipul Parekh <[log in to unmask]>
> > wrote:
> > 
> > Hello Tom, 
> > 
> > 
> > I appreciate your response greatly, thank you.
> > 
> > 
> > Re: your suggestion, "you’d need to provide some highly motivating
> > use cases", well I wonder what, if anything, might quality as
> > motivating!?  For me, the immediate use case is with trying to roll
> > my own strongly-typed and scoped ENUM facility in my Fortran, along
> > the lines of enhanced enum introduced in C++ starting with 11
> > standard revision -
> > see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf.
> > 
> > 
> > Re: enumerations, you may be aware of some recent threads at
> > comp.lang.fortran:
> > https://groups.google.com/forum/#!
> > searchin/comp.lang.fortran/FortranFan$20enum%
> > 7Csort:relevance/comp.lang.fortran/iWUgXY0UJ4s/LoPqAJggEAAJ 
> > 
> > https://groups.google.com/forum/#!
> > searchin/comp.lang.fortran/FortranFan$20enum%
> > 7Csort:relevance/comp.lang.fortran/Kc15pVHxOQg/f6e5pEBzDgAJ 
> > 
> > https://groups.google.com/forum/#!
> > topic/comp.lang.fortran/W70llWwUBHw
> > 
> > 
> > 
> > So what I have currently is a simple-minded implementation of a
> > parameterized ABSTRACT derived type that has all bindings with the
> > generic interfaces for required operations such as == and /= and
> > UDDTIO, etc. but it also needs a public "val" integer component.  So
> > for any particular ENUM that is desired, say Days, there is an
> > extension type for it from the abstract base with one additional
> > type-bound procedure which is a setter method that extends the
> > generic assignment taking the extension type as RHS.  Additionally I
> > use the common Fortran 95 trick with a "collection" type whose
> > components are each extension type (as in Sunday, Monday, etc.) and
> > finally I include a "named constant" of said collection.  With such
> > design, one can consume the 'enums' with code like so:
> > ..
> >    use Day_m, only : Day, Days  ! Day is a derived type; Days is a named constant
> >    ..
> > 
> >    type(Day) :: Today   
> > 
> >    Today = Days%Wednesday
> >    !Today = 2  ! compiler error; not allowed as intended due to strong typing
> > select case ( Today%val )        !** Would like NOT to access the Val component in this construct
> >       case ( Days%Wednesday%val )
> >          print *, "Hey, Pay Day!"
> >       case ( Days%Friday%val )
> >          print *, "TGIF!"
> >       case ( Days%Saturday%val, Days%Sunday%val )
> >          print *, "It's a weekend!"
> >       case default
> >          print *, "Bad day in a cube farm :-("
> >    end select
> > 
> >    print *, "Today is ", Today   !  UDDTIO in effect; expected output is Today is Wednesday
> >    ..
> > 
> > 
> > Note also the above derived type implementation allows for enum-like
> > facility in procedure arguments, as components of other derived
> > types ('classes'), and so forth.
> > 
> > 
> > But sure if a future Fortran standard were to include an enhanced
> > ENUM facility (something which I had brought up on this mailing list
> > back in March), my immediate use case disappears but I think the
> > concept of an improved SELECT CASE with certain designs of derived
> > types is still worthy of consideration.
> > 
> > 
> > Please note I fully realize all of this falls only in the category
> > of "syntactic sugar", so why bring it up all?  Because I work in
> > industry and boy, do Fortranners need some helping hand here!
> > 
> > 
> > Between C++, C# (more like Microsoft .NET), Python, MATLAB, and
> > Excel/VBA, the space for Fortran in industry can soon shrink to
> > nothingness unless Fortran quickly fills some gaps in helping coders
> > write expressive, efficient, and easy-to-maintain code (productivity
> > is very important in industry) while retaining the power of numeric
> > computing such as array handling and now coarrays.
> > 
> > 
> > I'm immediately drawn to all the 'goodies' that can be made
> > available to Fortranners which can then make Fortran code robust and
> > yet expressive and easy-to-read.  I think it's getting very close
> > with 'modern Fortran' syntax.  With a few options included in the
> > standard and with improving editors, toolchains and IDEs, the
> > overall experience can be greatly improved.  Once this is realized,
> > the managers and purse-string holders can be more readily convinced
> > to reinvest in Fortran for more computing needs in industry.  That's
> > my motivation - how is that for a use case?!!
> > 
> > 
> > Best Regards,
> > Vipul
> > 
> > 
> > 
> > 
> > 
> > On Tue, Oct 25, 2016 at 9:46 AM, Clune, Thomas L. (GSFC-6101)
> > <[log in to unmask]> wrote:
> >         Hi Vipul, 
> >         
> >         
> >         I think you’d need to provide some highly motivating use
> >         cases.    In my experience it is relatively unusual to have
> >         derived type PARAMETERs.    One of the major reasons for
> >         this is that PRIVATE components within a derive type will
> >         generally prevent PARAMETERs of that derived type.
> >         Also note that the structure is intended to work with CASE(…
> >         ) values that are known at _compile_ time.   E.g., the
> >         standard does not even support the following:
> >         
> >         
> >              INTEGER :: i, j, k
> >              SELECT CASE (i)
> >              CASE (j)
> >                   …
> >              CASE (k)
> >                   …
> >              END SELECT
> >         
> >         
> >         Other things for you to consider:
> >         
> >         
> >         1) The standard does not even support SELECT TYPE for REAL
> >         and COMPLEX types.    I’ve only been on the committee for a
> >         short time, but I suspect there has not been much demand for
> >         these.
> >         
> >         
> >         2) The compiler needs to know how to detect which case
> >         applies?   You apparently ntended your hash to provide that
> >         definition, but in that case you can already do what you
> >         want.  Just use the hash directly:
> >         
> >         
> >               SELECT TYPE (bar%get_hash_code())
> >               CASE (COMPILE_TIME_KNOWN_HASH_OF_FOO)
> >                   …
> >               CASE default
> >                   …
> >                END SELECT
> >         
> >         
> >         
> >         
> >         Of course, you’d need to find a method to know the hash of
> >         foo at compile time, which is possibly problematic in
> >         practice.
> >         
> >         
> >         Cheers,
> >         
> >         
> >         - Tom
> >         
> >         
> >         
> >         
> >         
> >         
> >         
> >         
> >         
> >         
> >         
> >         
> >         
> >         > On Oct 25, 2016, at 9:00 AM, Vipul Parekh
> >         > <[log in to unmask]> wrote:
> >         > 
> >         > Van, 
> >         > 
> >         > 
> >         > Please Tom's comment, it's indeed as he writes.
> >         > 
> >         > 
> >         > Tom,
> >         > 
> >         > 
> >         > Thanks much for your feedback.
> >         > 
> >         > 
> >         > To all those who are on the standard committee or have
> >         > interactions with someone who's on the committee:
> >         > 
> >         > 
> >         > Is it possible for someone to give the suggestion in my
> >         > original post some thought?
> >         > 
> >         > 
> >         > Thanks,
> >         > Vipul
> >         > 
> >         > On Mon, Oct 24, 2016 at 4:58 PM, Clune, Thomas L.
> >         > (GSFC-6101) <[log in to unmask]> wrote:
> >         >         Van,
> >         >         
> >         >         No - I think the poster actually wanted to use
> >         >         SELECT CASE.   He has provided a parameter ‘foo’,
> >         >         and wants to check if it is the same value as
> >         >         ‘bar’.   Although inheritance was used, all of the
> >         >         variables are of type ’t’.
> >         >         
> >         >         One can overload ‘==‘ in Fortran, but SELECT CASE
> >         >         is currently limited to only a subset of intrinsic
> >         >         types.   I’ve not seen any proposals for
> >         >         extensions to derived types.
> >         >         
> >         >         - Tom
> >         >         
> >         >         
> >         >         > On Oct 24, 2016, at 4:23 PM, Van Snyder
> >         >         <[log in to unmask]> wrote:
> >         >         >
> >         >         > If I understand your question correctly, what
> >         >         you want to use is SELECT
> >         >         > TYPE instead of SELECCT CASE.
> >         >         >
> >         >         > On Mon, 2016-10-24 at 16:11 -0400, Vipul Parekh
> >         >         wrote:
> >         >         >> I would like to be able to use some of my OO
> >         >         'classes' (derived types)
> >         >         >> in SELECT CASE constructs like so:
> >         >         >>
> >         >         >>
> >         >         >> -- begin pseudo code snippet --
> >         >         >> program p
> >         >         >>
> >         >         >>
> >         >         >>   use m, only : t, foo
> >         >         >>
> >         >         >>
> >         >         >>   type(t) :: bar
> >         >         >>
> >         >         >>
> >         >         >>   ! The following is not possible with even
> >         >         proposed Fortran 2015
> >         >         >> draft
> >         >         >>
> >         >         >>   !select case ( bar )
> >         >         >>   !   case ( foo )
> >         >         >>   !      print *, "bar == foo"
> >         >         >>   !   case default
> >         >         >>   !      print *, "bar /= foo"
> >         >         >>   !end select
> >         >         >>
> >         >         >>
> >         >         >>   stop
> >         >         >>
> >         >         >>
> >         >         >> end program p
> >         >         >> module  m
> >         >         >>
> >         >         >>
> >         >         >>   use, intrinsic :: iso_fortran_env, only :
> >         >         ISO_FORTRAN_ADT,
> >         >         >> ISO_FORTRAN_IGETHASHCODE
> >         >         >>
> >         >         >>
> >         >         >>   implicit none
> >         >         >>
> >         >         >>
> >         >         >>   private
> >         >         >>
> >         >         >>
> >         >         >>   type, extends(ISO_FORTRAN_ADT), public :: t
> >         >         >>      private
> >         >         >>      integer :: m_i = 42
> >         >         >>   contains
> >         >         >>      private
> >         >         >>      procedure(ISO_FORTRAN_IGETHASHCODE),
> >         >         pass(this) :: get_hash_code
> >         >         >>   end type t
> >         >         >>
> >         >         >>
> >         >         >>
> >         >         >>   type(t), parameter, public :: foo = t( m_i=99
> >         >         )
> >         >         >>
> >         >         >>
> >         >         >> contains
> >         >         >>
> >         >         >>
> >         >         >>   subroutine get_hash_code( this )
> >         >         result( hash_code )
> >         >         >>
> >         >         >>
> >         >         >>      class(this), intent(in)   :: this
> >         >         >>
> >         >         >>      integer :: hash_code
> >         >         >>
> >         >         >>
> >         >         >>      hash_code = ..
> >         >         >>
> >         >         >>
> >         >         >>      return
> >         >         >>
> >         >         >>
> >         >         >>   end subroutine get_hash_code
> >         >         >>
> >         >         >>
> >         >         >> end module m
> >         >         >>
> >         >         >> -- end pseudo code snippet --
> >         >         >>
> >         >         >>
> >         >         >>
> >         >         >> Is there any proposal/discussion in a future
> >         >         Fortran revision that
> >         >         >> will allow the above?
> >         >         >>
> >         >         >>
> >         >         >> I wonder if the standard were to introduce some
> >         >         "intrinsic" abstract
> >         >         >> derived type (say ISO_FORTRAN_ADT) with some
> >         >         deferred type-bound
> >         >         >> procedure, say ISO_FORTRAN_IGETHASHCODE, that
> >         >         provides an integer
> >         >         >> (default kind even) function result with a hash
> >         >         code for the type and
> >         >         >> I extend my types from this abstract to supply
> >         >         a hash code for the
> >         >         >> type, then why can't the SELECT CASE construct
> >         >         be allowed to operate
> >         >         >> on such derived types in addition to the
> >         >         current facility to work with
> >         >         >> integer, logical, and real intrinsic types?
> >         >         >>
> >         >         >>
> >         >         >> Thanks,
> >         >         >> Vipul Parekh
> >         >         
> >         > 
> >         > 
> >         
> >         
> > 
> > 
> 
> 

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