오류 FS1133 : '목록 <'a> '유형에 사용할 수 없습니다.
-
14-11-2019 - |
문제
나는 괜찮아요.
type Person =
{ First: string; Last : string }
override this.ToString() = sprintf "%s, %s" this.First this.Last
.
하지만 다음과 같이 사람의 목록을 만들려고 할 때.
let people =
new List<_>(
[|
{First = "Bhushan"; Last = "Shinde"}
{ First = "Abhi"; Last = "Jad"}
|])
.
오류가 발생합니다. 유형 '목록 <'a> ' 유형에 사용할 수 없습니다
누군가가 문제가 무엇인지 설명 할 수 있습니까?
고맙습니다.
해결책
In F#, the name List<_>
is used to refer to the immutable F# list (defined in F# core library).
If you want to create mutable .NET list (System.Collections.Generic.List<_>
), you need to use an alias that is defined in the F# library ResizeArray<_>
(or you need to use fully qualified name):
let people =
new ResizeArray<_>(
[|
{First = "Bhushan"; Last = "Shinde"}
{ First = "Abhi"; Last = "Jad"}
|])
If you want to create a normal F# list (and use it in a functional style), then you can just use the list comprehension syntax without passing the value to any constructor:
let people =
[ {First = "Bhushan"; Last = "Shinde"}
{ First = "Abhi"; Last = "Jad"} ]
제휴하지 않습니다 StackOverflow