!Bad f95, and f95 compilers must say so because the F95 standard's 3rd 
!constraint after R523 says that functions with results or arguments of
!private type (e.g. rtype, string1 respectively) can't have public generic 
!identifiers.
!
!F2003 and 2008 do not have that Constraint.

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

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

  pure character(80) function string1(stuff1)
    type(char1int),intent(in)::       stuff1
    write(string1,'(A," kind = ",I0)') stuff1
  end function string1

  pure character(80) function string2(stuff2)
    type(char2int),intent(in)::       stuff2
    write(string2,'(A," kind = ",I0," len = ",I0)') stuff2
  end function string2

end module whattype

program testpublic
  use whattype
  implicit none
  character(80) string
  string = reveal(datatype("rhubarb"))
  print *, ' "rhubarb" is '//trim(string)
  string = reveal(datatype(666.0))
  print *, ' 666.0     is '//trim(string)
end program testpublic
