type-bounds

OOP Fortran, Type and Procedures in different files

隐身守侯 提交于 2021-02-11 05:52:35
问题 I was wondering whether it is possible to place the actual subroutines behind type bound procedures and the type definition in different files. EG: File A: Module TypeDef Type :: Test Integer :: a,b,c contains Procedure, Pass, Public :: add => SubAdd End Type Type(Test) :: Test Interface Subroutine SubAdd(this) Import TypeDef Class(TypeDef), Intent(InOut) :: this End Subroutine End Interface End Module File B: Module TypeRoutines use TypeDef Private :: SubAdd contains Subroutine SubAdd(this)

OOP Fortran, Type and Procedures in different files

▼魔方 西西 提交于 2021-02-11 05:52:19
问题 I was wondering whether it is possible to place the actual subroutines behind type bound procedures and the type definition in different files. EG: File A: Module TypeDef Type :: Test Integer :: a,b,c contains Procedure, Pass, Public :: add => SubAdd End Type Type(Test) :: Test Interface Subroutine SubAdd(this) Import TypeDef Class(TypeDef), Intent(InOut) :: this End Subroutine End Interface End Module File B: Module TypeRoutines use TypeDef Private :: SubAdd contains Subroutine SubAdd(this)

OOP Fortran, Type and Procedures in different files

风流意气都作罢 提交于 2021-02-11 05:52:07
问题 I was wondering whether it is possible to place the actual subroutines behind type bound procedures and the type definition in different files. EG: File A: Module TypeDef Type :: Test Integer :: a,b,c contains Procedure, Pass, Public :: add => SubAdd End Type Type(Test) :: Test Interface Subroutine SubAdd(this) Import TypeDef Class(TypeDef), Intent(InOut) :: this End Subroutine End Interface End Module File B: Module TypeRoutines use TypeDef Private :: SubAdd contains Subroutine SubAdd(this)

Prove that a runtimeClass satisfies a type Bound in Scala

坚强是说给别人听的谎言 提交于 2021-02-08 08:37:16
问题 I have a method that writes one of my classes Foo , which is defined as Thrift, in Parquet form. import Foo import org.apache.spark.rdd.RDD import org.apache.thrift.TBase import org.apache.hadoop.mapreduce.Job import org.apache.parquet.hadoop.ParquetOutputFormat import org.apache.parquet.hadoop.thrift.ParquetThriftOutputFormat def writeThriftParquet(rdd: RDD[Foo], outputPath: String): Unit = { val job = Job.getInstance() ParquetThriftOutputFormat.setThriftClass(job, classOf[Foo])

What is the correct way to implement trait with generics in Scala?

天大地大妈咪最大 提交于 2020-12-09 02:23:41
问题 I have some simple traits (Entity in the example below) that are extended by case classes in my app. I would like to create an EntityMapper trait that provides an interface for handling the case classes that extend the Entity trait (Foo in the example below). I thought I should be able to do this fairly easily using generics and bounding but I've spent a couple of hours on it already and I haven't gotten it to work correctly. The code below is what I think I should be able to do but it fails

Why can't I return a concrete subtype of A if a generic subtype of A is declared as return parameter?

和自甴很熟 提交于 2020-05-24 06:08:11
问题 abstract class IntTree object Empty extends IntTree case class NonEmpty(elem: Int, left: IntTree, right: IntTree) extends IntTree def assertNonNegative[S <: IntTree](t: S): S = { t match { case Empty => Empty // type mismatch, required: S, found: Empty.type case NonEmpty(elem, left, right) => if (elem < 0) throw new Exception else NonEmpty(elem, assertNonNegatve(left), assertNonNegative(right)) // req: S, fd: NonEmpty.type } } This is my failed attempt of implementing the function with

Underscores in type bounds on type constructors

不打扰是莪最后的温柔 提交于 2020-01-13 09:17:47
问题 Can someone explain why the following doesn't compile? I want that BB[A] is also a List[A] . The method body only enforces this view. scala> def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]} <console>:8: error: type mismatch; found : BB[A] required: List[A] def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]} ^ 回答1: I think you need to name the _ parameter. scala> def x[A, BB[X] <: List[X]](p: BB[A]) {p: List[A]} works. 来源: https://stackoverflow.com/questions/6492934/underscores-in-type-bounds

Scala inferred type arguments - Type bounds inferring to 'Nothing'

北战南征 提交于 2020-01-02 03:13:24
问题 I'm attempting to write a simple query monad and am having trouble getting my generic type annotations correct. My first attempt went as follows (vastly simplified for conciseness) case class Person( val name: String ) abstract class Schema[T] object People extends Schema[Person] case class Query[U <: Schema[T], T]( schema: U ) { <---- Type signature def results: Seq[T] = ... def where( f: U => Operation ) = ... } class TypeText extends Application { val query = Query( People ) <---- Type

Scala Abstract type members - inheritance and type bounds

落爺英雄遲暮 提交于 2020-01-01 12:25:10
问题 I ran into some strange situation in Scala today while I tried to refine the type bounds on an abstract type member. I have two traits that define bounds on a type member and combine them in a concrete class. That works fine but when matching / casting with the trait combination only one of the two TypeBounds is "active" and I struggle to understand why ... I tried to prepare an example: trait L trait R trait Left { type T <: L def get: T } trait Right { type T <: R } now if I combine these