![](/img/trans.png)
[英]How do you define a Haskell typeclass with a type that cannot be deduced?
[英]How do you define a function type in Haskell?
我正在嘗試將 function 類型存儲在定義中,以便我可以重用它,但 Haskell 不允許我這樣做。 據我了解, function 類型不是data
類型,也不是class
。 那么我做錯了什么?
functionType = Int -> Int -> Int -> Int -> Int -> Int -> Int
myfunction :: functionType -- <-- how do I declare this thing in a definition?
myfunction a b c d e f = a*b*c*d*e*f
類型別名在其聲明中使用type
關鍵字; 此外,像往常一樣,對於新類型 forms 的聲明,新聲明的別名必須以大寫字母*開頭。 所以:
type FunctionType = Int -> Int -- -> ...
functionValue :: FunctionType
functionValue a = a
* ...或標點符號。 為什么通常的“大寫”標點限制不適用? 不知道。 在嘗試寫這個答案之前我從未想過它,現在我有,我覺得這有點奇怪。 也許應該刪除對新類型聲明的大寫限制!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.