English 中文(简体)
为什么这种声明发挥作用?
原标题:Why doesn t this type declaration work?
  • 时间:2009-12-31 05:59:46
  •  标签:
  • haskell

I m 试图在每个人都有性或姓名的情况下创造个人类型。

data Sex = Sex Char deriving Show

male   = Sex  M 
female = Sex  F 

data Name   = Name [Char]      deriving Show

data Person = Person { 
    Sex    :: Sex,
    Name   :: Name
} deriving (Show)

当我试图在格西里装上这段话时,我才发现无益的错误:输入中的错误

我在这里做了什么错误?

最佳回答

问题在于你在记录中使用了上一级案件。 守则应着眼于:

data Person = Person { sex :: Sex, name :: Name }...

守则似乎至少是编纂的。 由于“性别”和“姓名”不是类型(尽管“Sex”和“Name”),因此,你不能将第一封信函列为上。

问题回答

暂无回答




相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

热门标签