私はハスケルに新しいです、私は下の答えを見回しましたが、運がありませんでした。Haskell - データ型の結合?
なぜこのコードはコンパイルされませんか?
newtype Name = Name String deriving (Show, Read)
newtype Age = Age Int deriving (Show, Read)
newtype Height = Height Int deriving (Show, Read)
data User = Person Name Age Height deriving (Show, Read)
data Characteristics a b c = Characteristics a b c
exampleFunction :: Characteristics a b c -> User
exampleFunction (Characteristics a b c) = (Person (Name a) (Age b) (Height c))
エラー:
"Couldn't match expected type ‘String’ with actual type ‘a’,‘a’ is a rigid type, variable bound by the type signature"
しかし、これはうまくコンパイル:
exampleFunction :: String -> Int -> Int -> User
exampleFunction a b c = (Person (Name a) (Age b) (Height c))
私は上記を行うためのシンプルな方法があります実現が、私はただの異なる使用をテストしていますカスタムデータ型。
更新:
私の傾きがそのタイプセーフではないので、コンパイラは「exampleFunction ::特性B C」を好きではないということです。すなわち、私はa == Name String、b == Age Int、c == Height Intの保証を提供していません。
おかげで、私はほとんどこれと同時に、私の質問を更新し、いくつかの説明を追加し、エラーを説明していない:P –