小编sha*_*yan的帖子

为什么 Haskell 的“通用”类类型系列“Rep a”被注释为类型构造函数,而不是类型?

考虑 Haskell 的Generic课程:

class Generic a where
  -- | Generic representation type
  type Rep a :: * -> *
  -- | Convert from the datatype to its representation
  from  :: a -> (Rep a) x
  -- | Convert from the representation to the datatype
  to    :: (Rep a) x -> a
Run Code Online (Sandbox Code Playgroud)

我很好奇为什么它没有写成如下:

class Generic a where
  -- | Generic representation type
  type Rep a :: *
  -- | Convert from the datatype to its representation
  from  :: a …
Run Code Online (Sandbox Code Playgroud)

haskell

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

为什么我不能从内部的任一投影中提取元组以使用模式匹配进行理解?

为什么这样做:

val somePair: Option[(String,String)] = Some(("John", "Doe"))
(for {
  pair <- somePair.toRight("Hello unknown!").right
} yield s"Hello ${pair._1} ${pair._2}!").merge
Run Code Online (Sandbox Code Playgroud)

但这不会:

val somePair: Option[(String,String)] = Some(("John", "Doe"))
(for {
  (name,lastName) <- somePair.toRight("Hello unknown!").right
} yield s"Hello $name $lastName!").merge
Run Code Online (Sandbox Code Playgroud)

编辑:
我应该添加这是错误消息:
Error:(43, 4) constructor cannot be instantiated to expected type; found : (T1, T2) required: scala.util.Either[Nothing,(String, String)] (name,lastName) <- somePair.toRight("Hello unknown!").right ^

scala either

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

GHC 推断我的歧义类型使约束成功

在我实现类型级编码树的早期阶段,当涉及类型约束时遇到不明确的类型时,我遇到了 GHC 在其类型推断中的特殊行为。我写了两个 AST 节点,如下所示,它们都可以通过它们实现的Typed类型类实例检查它们的类型:

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}

class Typed t where
  type T t

-- | A Literal node
newtype Lit a =
  Lit a

instance Typed (Lit a) where
  type T (Lit a) = a

-- | A Plus Node
data Plus a b =
  Plus a b

instance T a ~ T b => Typed (Plus a b) where
  type T (Plus a b) = T a 
Run Code Online (Sandbox Code Playgroud)

然后我编写了未类型检查的badPlus函数,它不对 …

haskell type-inference typeclass

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

Scala关于F#中"部分函数"和".orElse"方法的概念

在Scala中,"部分功能"的概念与F#的function关键字允许我实现的功能非常相似.然而,Scala的部分函数也允许通过orElse如下所示的方法进行合成:

def intMatcher: PartialFunction[Any,String] = {
  case _ : Int => "Int"
}

def stringMatcher: PartialFunction[Any,String] = {
  case _: String => "String"
}

def defaultMatcher: PartialFunction[Any,String] = {
  case _ => "other"
}

val msgHandler =
  intMatcher
  .orElse(stringMatcher)
  .orElse(defaultMatcher)

msgHandler(5) // yields res0: String = "Int"
Run Code Online (Sandbox Code Playgroud)

我需要知道是否有办法在F#中实现相同的组合功能.

f# scala partialfunction

3
推荐指数
2
解决办法
186
查看次数

在 amazon/aws-cli docker 映像上安装 python 3.9

如何在默认情况下附带 python 2.7 的 amazon/aws-cli docker 映像上安装 Python 3.9?到目前为止,我尝试过的是基于在 Amazon Linux 2 上安装 Python 3 的安装教程的以下一系列命令:

FROM amazon/aws-cli:latest

WORKDIR ./

COPY ./.aws ./root/.aws

COPY . .

RUN yum install gcc openssl-devel bzip2-devel libffi-devel -y
RUN yum install wget tar -y
RUN cd /opt
RUN wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
RUN tar xzf Python-3.9.6.tgz
RUN cd Python-3.9.6
RUN ./configure --enable-optimizations
RUN make altinstall
RUN rm -f /opt/Python-3.9.6.tgz

RUN ["python3", "-u", "app.py"]
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

[+] Building 13.5s (14/19)
 => [internal] load build definition from Dockerfile                       0.1s …
Run Code Online (Sandbox Code Playgroud)

python amazon-web-services python-3.x docker

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