小编Ørj*_*sen的帖子

Haskell:可以在函数定义中使用类型变量吗?

我有一个与Haskell类型系统有关的问题.这不是我第一次遇到类型系统的限制.我将省略我的项目详细信息并使用简化示例.这是一些代码:

-- Works
foo :: (Bounded a, Enum a) => a
foo = minBound

-- "ambiguous" constraint:
-- 'a' has no occurrences in type declaration
bar :: (Bounded a, Enum a) => Int
bar = fromEnum minBound

-- Too much information in return
-- but I can show haskell the appropriate type of 'min'
baz :: (Bounded a, Enum a) => (a, Int)
baz = let min = minBound
    in (min, someFunction . fromEnum $ min)

-- Type constraint 'a' …
Run Code Online (Sandbox Code Playgroud)

haskell types

13
推荐指数
1
解决办法
491
查看次数

标签 统计

haskell ×1

types ×1