标签: pointfree

为什么不这个类型检查呢?

compress xs@(_:_:_) = (ifte <$> ((==) <$> head <*> head.tail) <$> ((compress.).(:) <$> head <*> tail.tail) <*> ((:) <$> head <*> compress.tail) ) xs

导致类型错误,但我不明白为什么.它应该相当于

compress xs@(_:_:_) = (ifte (((==) <$> head <*> head.tail) xs) (((compress.).(:) <$> head <*> tail.tail) xs) (((:) <$> head <*> compress.tail) xs))

,没有.

注意:ifte = (\ x y z -> if x then y else z),<$><*>Control.Applicative.

编辑:错误是:

Couldn't match expected type `[a]' with actual type `[a] …
Run Code Online (Sandbox Code Playgroud)

debugging haskell types typechecking pointfree

0
推荐指数
2
解决办法
202
查看次数

Haskell实用程序使函数点免费

我想快速正确地减少函数以在Haskell中指向自由格式.我更愿意产生相当可读的结果.我该怎么办呢?

haskell lambda-calculus pointfree combinatory-logic

0
推荐指数
1
解决办法
169
查看次数

Haskell:无点风格

为什么第一个失败而后者成功编译?

我期望foo并且foo'是等价的,也就是说,foo'它只是一个无点函数foo:

foo :: [a] -> [a] -> [(a,a)]
foo = map id . zip

foo' :: [a] -> [a] -> [(a,a)]
foo' a b = map id $ zip a b
Run Code Online (Sandbox Code Playgroud)

foo失败并出现以下错误:

Couldn't match type ‘[b0] -> [(a, b0)]’ with ‘[b]’
Expected type: [a] -> [b]
  Actual type: [a] -> [b0] -> [(a, b0)]
Relevant bindings include
  foo :: [a] -> [b] (bound at <interactive>:26:5)
Probable cause: ‘zip’ is …
Run Code Online (Sandbox Code Playgroud)

haskell pointfree

0
推荐指数
1
解决办法
243
查看次数

何时使用以及何时不在haskell中使用无点样式?

我刚学会了Haskell中的无点样式,以及它如何帮助整理代码并使其更易于阅读.但有时他们可以使代码有点过于简洁.

所以,当我应该总是使用无点样式时,在什么情况下我应该绝对避免在Haskell中使用无点样式?

haskell function pointfree

0
推荐指数
1
解决办法
132
查看次数

如何在haskell中使用列表理解来编写函数?

我已经编写了这个函数map,但是我需要使用list comprehension来编写它:

alter = map (\x -> if x == 0 then 1 else 0)
Run Code Online (Sandbox Code Playgroud)

它给出了例如

alter [1,1,0]  
> [0,0,1]
Run Code Online (Sandbox Code Playgroud)

haskell list-comprehension pointfree

0
推荐指数
1
解决办法
269
查看次数

在R.pipe中访问临时变量。拉姆达

假设我要计算平均费用:

const products = [
  {
     cost: 300
  },
  {
     cost: 700
  }
];
Run Code Online (Sandbox Code Playgroud)

因此,首先选择成本属性,对其进行汇总,然后除以项目的nr个。

const calcualteAveragePrice = R.pipe(
      R.map(R.prop('cost') // [300, 700]
      R.sum, // 1000
      R.divide(??) // How do I divide with the number of items here??
    )
Run Code Online (Sandbox Code Playgroud)

在最后一步中,我需要除以项目数。由于它是免费的,所以我不能arr.length

functional-programming pointfree ramda.js

0
推荐指数
1
解决办法
45
查看次数

将 2 个元素添加到列表的无点函数 / (:) 列表数据构造函数和 (.) 的双重应用

我正在努力正确定义该函数的无点版本,它将向列表添加 2 个元素。

\n

很容易想出一些简单的简单实现:

\n
addTwoElems :: a -> a -> [a] -> [a]\n\naddTwoElems x y xs = x : y : xs\naddTwoElems x y    = (++) [x, y]\naddTwoElems        = (.) `on` (:)  \xe2\x80\x9c point free but with additional function\n
Run Code Online (Sandbox Code Playgroud)\n

但是两个列表数据构造函数的无点组合(:)(.) 会是什么样子呢?

\n

请不仅展示正确的功能实现,还请解释如何获得正确版本的步骤和逻辑。

\n

syntax haskell functional-programming pointfree type-constructor

0
推荐指数
1
解决办法
110
查看次数

在Haskell中如何使函数表达式“无点”

我有一个像这样的 Haskell 函数:

in2out :: String -> String
in2out s = 
  show (sumAllLineValues $ lines s)
Run Code Online (Sandbox Code Playgroud)

(其中sumAllLineValues在我的代码中定义。)

我如何定义in2out无点,所以没有参数s

haskell pointfree

-2
推荐指数
1
解决办法
68
查看次数

如何用无点样式编写这个函数?

如何以无点样式重写以下函数,x完全从定义中删除参数(另外两个可能保留):

between min max x = (min < x) && (x < max)
Run Code Online (Sandbox Code Playgroud)

这不是一项任务,只是一个问题.我不知道该怎么办.我可以把它变成一个lambda函数

between min max = \x -> (min < x) && (x < max)
Run Code Online (Sandbox Code Playgroud)

但这不是没有点的,因为x它仍然存在.请帮忙.

haskell functional-programming pointfree tacit-programming

-12
推荐指数
2
解决办法
334
查看次数