小编use*_*628的帖子

如何在 Racket 中检查类型?

我定义了一个函数

(define 1-9 (list->set (range 1 10)))
Run Code Online (Sandbox Code Playgroud)

我想看看1-9是不是真的一套。我怎样才能得到类型1-9

我试图谷歌球拍检查类型,但我找不到任何有用的信息。

types racket

8
推荐指数
1
解决办法
5329
查看次数

<*>如何从纯粹和(>> =)派生?

class Applicative f => Monad f where
       return :: a -> f a
       (>>=) :: f a -> (a -> f b) -> f b
Run Code Online (Sandbox Code Playgroud)

(<*>)可以源自纯粹和(>>=):

fs <*> as =
    fs >>= (\f -> as >>= (\a -> pure (f a)))
Run Code Online (Sandbox Code Playgroud)

对于线

fs >>= (\f -> as >>= (\a -> pure (f a)))
Run Code Online (Sandbox Code Playgroud)

我很困惑的用法>>=.我认为它需要一个仿函数f a和一个函数,然后返回另一个仿函数f b.但在这个表达中,我感到迷茫.

monads haskell functor applicative

6
推荐指数
2
解决办法
140
查看次数

case 和 match 有什么区别?

我混淆了约之间的差异matchcase。在文件中?它提到match支持通用模式匹配。

> (define (m x)
    (match x
      [(list a b c)
       #:when (= 6 (+ a b c))
       'sum-is-six]
      [(list a b c) 'sum-is-not-six]))
> (m '(1 2 3))
'sum-is-six

> (m '(2 3 4))
'sum-is-not-six 
Run Code Online (Sandbox Code Playgroud)

对于这个例子,我想我可以使用case表达式重写它。不过好像挺复杂的。我必须获得输入的长度x,也许还需要一个 lambda 函数来获取 的元素总和x并将其与6.

所以我想我们更喜欢match做模式匹配。这是真的吗?除此之外还有什么区别吗?

case match racket

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

如何删除除 OS X 携带的所有其他 python 版本

在问这个问题之前,我尝试了很多方法。我主要关注这些帖子。

如何在 mac os x 上找到所有 python 安装并卸载除本机 OS X 安装之外的所有安装

如何清理 iPython 环境以便我可以重新开始使用 Jupyter 和 Python 3.x?

我也试过

conda install anaconda-clean
anaconda-clean --yes
rm -rf ~/anaconda3
Run Code Online (Sandbox Code Playgroud)

brew cleanup python3

但我还有很多 python 版本

GZs-MacBook-Pro:bin gz$ which python
/usr/bin/python
GZs-MacBook-Pro:bin gz$ which python3
/usr/bin/python3
GZs-MacBook-Pro:bin gz$ ls /System/Library/Frameworks/Python.framework/Versions
2.3 2.5 2.6 2.7 Current
GZs-MacBook-Pro:bin gz$ ls /Library/Frameworks/Python.framework/Versions
ls: /Library/Frameworks/Python.framework/Versions: No such file or directory
GZs-MacBook-Pro:bin gz$ ls -l /usr/bin/python*
lrwxr-xr-x  1 root  wheel     75  9 Oct 23:42 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x …
Run Code Online (Sandbox Code Playgroud)

python unix macos uninstallation python-3.x

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

安装 apache-airflow 时如何解决 requests 和 zipp 不兼容的问题?

我正在按照视频教程“Windows 10 上的 Apache Airflow 安装”来安装 apache-airflow。当我pip install apache-airflow在 WSL2 Ubuntu 中执行此操作时,它会提示

\n
ERROR: apache-airflow-providers-http 2.0.3 has requirement requests>=2.26.0, but you\'ll have requests 2.22.0 which is incompatible.\nERROR: importlib-resources 5.4.0 has requirement zipp>=3.1.0; python_version < "3.10", but you\'ll have zipp 1.0.0 which is incompatible.\n
Run Code Online (Sandbox Code Playgroud)\n

提供更多细节,看起来像这样

\n
Collecting apache-airflow\n  Downloading apache_airflow-2.2.4-py3-none-any.whl (5.3 MB)\n     |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 5.3 MB 4.1 MB/s\nRequirement already satisfied: cryptography>=0.9.3 in /usr/lib/python3/dist-packages (from apache-airflow) (2.8)\nCollecting markdown<4.0,>=2.5.2\n  Downloading Markdown-3.3.6-py3-none-any.whl (97 kB)\n     |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 97 kB 4.4 MB/s\nCollecting sqlalchemy<1.4.0,>=1.3.18\n …
Run Code Online (Sandbox Code Playgroud)

airflow

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

Dijkstra算法的时间复杂度是多少

Dijkstra((V, E)):\n  S = {}    //O(1)\n  for each vertex v \xe2\x88\x88 V:    //O(V)\n    d[v] = \xe2\x88\x9e    //O(1)\n  d[source] = 0    //O(1)\n  while S != V:    //O(V)\n    v = non visited vertex with the smallest d[v]    //O(V)\n    for each edge (v, u):    //O(E)\n      if u \xe2\x88\x88/ S and d[v] + w(v, u) < d[u]:\n        d[u] = d[v] + w(v, u)\n    S = S \xe2\x88\xaa {v}\n
Run Code Online (Sandbox Code Playgroud)\n\n

注意:\xe2\x88\x88/ 表示不在,我无法在代码中键入它。

\n\n

这个问题可能与某些帖子重复。

\n\n

了解 Dijkstra 算法的时间复杂度计算\n

\n\n

Dijkstra 算法的复杂性

\n\n

Dijkstras 算法的复杂性

\n\n …

dijkstra time-complexity

4
推荐指数
1
解决办法
6263
查看次数

如何在c中读取图像的像素?

假设我们的位图图像具有高度 M 和宽度 N。在本实验中,我们将始终假设宽度 N 是 4 的倍数,这简化了文件中的字节布局。对于此图像,像素阵列以以下方式存储 3 x N x M 字节:

每组 3 个字节代表一个像素,其中字节按此顺序存储像素的蓝色、绿色和红色值。

像素按行分组。例如,像素阵列中的前 3 x N 个字节表示图像最顶行中的像素。

pixel_array_offset 是像素阵列开始的地方。

一个结构像素给出如下:

struct pixel {
    unsigned char blue;
    unsigned char green;
    unsigned char red;
};
Run Code Online (Sandbox Code Playgroud)

这是实现该功能的要求:

/*
 * Read in pixel array by following these instructions:
 *
 * 1. First, allocate space for m "struct pixel *" values, where m is the
 *    height of the image.  Each pointer will eventually point to one row of
 * …
Run Code Online (Sandbox Code Playgroud)

c

4
推荐指数
1
解决办法
4261
查看次数

cons操作是否从右到左构成要素?

我们知道1:2:[]会回来[1,2].

我刚试过1:2,这给了我一个错误.

<interactive>:48:1: error:
    ? Non type-variable argument in the constraint: Num [a]
      (Use FlexibleContexts to permit this)
    ? When checking the inferred type
        it :: forall a. (Num a, Num [a]) => [a]
Run Code Online (Sandbox Code Playgroud)

我知道这可能不是一个恰当的例子,因为:操作包含元素和列表.但我只是想知道它是如何运作的1:2:[]

haskell syntactic-sugar operator-precedence cons

3
推荐指数
1
解决办法
105
查看次数

在什么条件下我们应该在类型声明中使用`[] a`?

我只看到一个表达

fmap_List :: (a -> b) -> [] a -> [] b
-- "[] a" means "[a]", for types.
fmap_List f [] = []
fmap_List f (x:xs) = f x : fmap_List f xs
Run Code Online (Sandbox Code Playgroud)

既然[] a意味着[a],为什么我们不[a]直接放?我们应该使用一些特殊情况[] a吗?

haskell type-declaration

3
推荐指数
1
解决办法
122
查看次数

'.++'的固定签名缺少附带绑定

infixr 5 .++
Run Code Online (Sandbox Code Playgroud)

我在ghci中这样做,它给出了错误消息.

<interactive>:26:10: error:
    The fixity signature for ‘.++’ lacks an accompanying binding
Run Code Online (Sandbox Code Playgroud)

我该如何解决?谢谢!

haskell

3
推荐指数
1
解决办法
294
查看次数