相关疑难解决方法(0)

Lambda用于Haskell中的类型表达式?

Haskell或特定编译器是否具有类型级lambda(如果这甚至是一个术语)?

详细说,我说有一个参数化类型,Foo a b并希望Foo _ b成为一个实例,比如Functor.是否有任何机制可以让我做类似的事情

instance Functor (\a -> Foo a b) where
...
Run Code Online (Sandbox Code Playgroud)

lambda haskell

25
推荐指数
4
解决办法
5406
查看次数

为什么(a,a)不是算子?

可能重复:
制作(a,a)一个Functor

我编写了以下quicksort实现:

import Data.List (partition)

quicksort [] = []

quicksort (x:xs) =
    let (smaller, notSmaller) = partition (< x) xs
    in  quicksort smaller ++ x : quicksort notSmaller
Run Code Online (Sandbox Code Playgroud)

然后我想quicksort通过应用fmap列表对来缩短两个递归调用:

quicksort (x:xs) =
    let (smaller, notSmaller) = fmap quicksort $ partition (< x) xs
    in  smaller ++ x : notSmaller
Run Code Online (Sandbox Code Playgroud)

但显然,(a, a)这不是一个算符.这是为什么?我试图提供一个:

instance Functor (a, a) where
    fmap f (x, y) = (f x, f y)
Run Code Online (Sandbox Code Playgroud)

但是ghci不喜欢我的尝试:

Kind mis-match
The first argument of `Functor' …
Run Code Online (Sandbox Code Playgroud)

haskell type-systems functor typeclass

7
推荐指数
1
解决办法
577
查看次数

这个管道元组运算符在某个地方已经存在了吗?

我知道(||>)哪个了(a' * 'b) -> ('a -> b' -> 'c) -> 'c

但我发现这非常有用,并想知道我是否重新发明了轮子:

// ('a * 'a) -> ('a -> 'b) -> ('b * 'b)
let inline (|>>) (a,b) f = (f a, f b)
Run Code Online (Sandbox Code Playgroud)

(*它可能发生,我ceil半小时前才发现这个功能!)

f# tuples pipe operators

5
推荐指数
1
解决办法
838
查看次数

标签 统计

haskell ×2

f# ×1

functor ×1

lambda ×1

operators ×1

pipe ×1

tuples ×1

type-systems ×1

typeclass ×1