scala - What does HList#foldLeft() return? -
I want to play unconscious with HList.
This is my first attempt:
attribute column [t] {val name: string} case class cv [t] (call: column [t], value: T) Object CV {Object column Cortex poly2 extended DF isolation [A] = ([string, string, string], cv [a]] {case ((suffix, separator, esula), cv) ⇒ (suffix, separator, if (SQL == "" cv.col.name + Suffix another sql + separator + cv.col.name + suffix)}} def alliance [a & lt;: HList] (column: A, suffix: string, separator: String = "and") (difference Inferior L: Left Folder [A, (String, String, String), ColumnMinator.product]): String = Column. Fold Lift ((suffix, separator, "")) (column coordinator). 3)
The problem is I do not know that foldLeft
returns in this example.
I hope that this will return (string, string, string)
, but the compiler says I return that l.ut
. l.ut
is
The source code is a little complicated to estimate.
There is more information about this in the web.
gives your alliance
method, which is called a, which means its return type depends on one of its logic - in this case Path-dependent type in which l
is included in its path.
In many cases, the compiler will know something about a stable dependent return type, but in your example it is not. Why do I explain each other, but first consider the following example:
scala> Characteristic Fu {Type A; Def a: A} Defined attribute Foo scala & gt; DefEfA (FU: Foo): F.U.A. = FAA FAA: (Foo: Foo) AF. A Scala & gt; FooA (new foo {type A = String; def a = "I'm a StringFoo"}) res0: string = a stringfoo
here inferred type Res0
Is string
, since the compiler knows statically that a
is the foo
argument string
. We can not write any of the following, though:
scala> Def fooA (foo: Foo): string = foo.a & lt; Console & gt ;: 12: Error: Type Mismatch; Found: foo.A required: string def fooA (foo: Foo): string = foo.a ^ scala & gt; Def fooA (foo: Foo) = foo.a.substring & lt; Console & gt;: 12: error: the value is not a member of substrings fu. A def fooA (foo: Foo) = foo.a.substring ^
Because here the compiler is not sure whether foo.A
is String
.
Here is a more complex example:
Seal Attribute Buzz {Type A Type B def b: B} Object Buzz {DIF MacBase [T] (T: T) : Falcon {type A = T; Type B = T} = New falcon {Type A = T type B = T def B = T}}
Now we know that this is not possible There are different types, but not the compiler, for B
and A
and B
, so this will not accept the following:
Scala> Def bazB (baz: falcon {type a = string}): string = buz. B & lt; Console & gt ;: 13: Error: Type Mismatch; Found: baz.b required: string def bazB (baz: baz {type a = string}): string = baz.b ^
This is what you are looking for. If we make the code unformed, we can understand ourselves that LeftFolder
we are making here in
and out
, But the compiler (or not - it can not make a design decision) can follow us in this argument, which means that this will not happen as a tuple without much evidence to us. Treat l.ut
.
Fortunately this is easy to provide thanks for the LeftFolder.Aux
, with LeftFolder
for Out
There is a nickname
def alliance [a & lt;: HList] (column: A, suffix: string, separator: string = "And") (implicit L: (string, string, string)]: string = column. Fold lift ((suffix, separator, "")) (column code) 3
(You can also use the type of member syntax in the plain old leftfolder
with the type of l
This signature can also make messengers.)
columnss.foldLeft (...) (...)
part still returns l.ut
, But now the compiler knows precisely that it is a tuple of strings.
Comments
Post a Comment