!Bad f95, and f95 compilers must say so because the F95 standard's 3rd 
!constraint after R523 says that functions of private type can't have 
!public generic identifiers.
!
!Also, the F95 standard 9.42 above Note 9.26 says
!"A derived-type object shall not appear as an input/output list item if any
!component ultimately in the object is not accessible within the scoping 
!unit containing the input/output statement."
!
!F2003 does not have that Constraint, and 9.5.2 after Note 9.35 says:
!"If a list item of derived type in a formatted input/output statement is 
!not processed by a user-defined derived-type input/output procedure, that 
!list item is treated as if all of the components of the list item were 
!specified in the list in component order; those components shall be 
!accessible in the scoping unit containing the input/output statement and 
!shall not be pointers or allocatable."
!
!That is not in a Constraint, so if the quoted wording forbids this program 
!then f2003 compilers are not required to say so.

module whattype
  private
  public datatype
  interface datatype
     module procedure rtype,chtype
  end interface datatype
  type char1int
     character(9) name
     integer      sort
  end type char1int
  type char2int
     Character(9) name
     Integer      sort
     Integer      leng
  end type char2int
contains
  elemental type(char1int) function rtype(x)
    real,intent(in)::                     x
    rtype = char1int('real',kind(x))
  end function rtype

  elemental type(char2int) function chtype(string)
    character(*),intent(in)::              string
    chtype = char2int('character',kind(string),len(string))
  end function chtype

end module whattype

program testpublic
  use whattype
  print 999, ' "rhubarb" is ',datatype("rhubarb")
  print 999, ' 666.0     is ',datatype(666.0)
999 format (2A,' kind = ',I0,:,' len = ',I0)
end program testpublic
