简体   繁体   中英

Using type variable from declaration in function

I'm quite new to Haskell and I'm trying to use a type variable from the function declaration in the creation (not quite sure what to call this in Haskell) of a record type.
As always, code explains my problem a lot better:

data S a = S {x::a}

f :: a -> S a
f n = (S a){x=n}

GHC says that a is not in scope on the last line. How could this be accomplished?

使用fn = S {x=n} ,不需要类型变量

如果确实需要声明中的类型变量,请使用作用域类型变量扩展名。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM