我熟悉的NEWTYPE声明:新类型声明函数?
newtype MyAge = Age {age :: Int} deriving (Show, Eq, Ord)
在这种情况下年龄是int,但是我遇到下面的代码,我无法理解这一点:
newtype Ages a = Ages {age :: String -> [(a,String)]}
这似乎是一个函数声明? (接受字符串,返回包含'a'和字符串的元组列表) - 这是正确的吗?
N.B我刚刚意识到这只是声明函数的基本记录语法。
此外,我试图实现这种类型的,但我必须做一些错误:
newtype Example a = Example {ex :: Int -> Int}
myexample = Example {ex = (\x -> x + 1)}
这将编译,但我不明白为什么,因为我没有通过' '参数?
不要将新问题添加到现有帖子。也就是说,'Example a'是使用[phantom type](https://wiki.haskell.org/Phantom_type)的一个例子。 – chepner