haskell

Is it possible to write join down for Arrows, not ArrowApply?

断了今生、忘了曾经 提交于 2020-08-19 07:29:36
问题 I tried writing down joinArr :: ??? a => a r (a r b) -> a r b . I came up with a solution which uses app , therefore narrowing the a down to ArrowApply 's: joinArr :: ArrowApply a => a r (a r b) -> a r b joinArr g = g &&& Control.Category.id >>> app Is it possible to have this function written down for arrows? My guess is no. Control.Monad.join could have been a good stand-in for >>= in the definition of the Monad type class: m >>= k = join $ k <$> m . Having joinArr :: Arrow a => a r (a r b)

Unit testing IO Int and similar in Haskell

浪尽此生 提交于 2020-08-19 04:19:04
问题 From Ninety-Nine Haskell Problems: Question 23: Extract a given number of randomly selected elements from a list. This is a partial solution. For simplicity, this code just selects one element from a list. import System.Random (randomRIO) randItem :: [a] -> IO a randItem xs = do i <- randomRIO (0,length xs - 1) return $ xs !! i so randItem [1..10] would return an IO Int that corresponds to (but does not equal) some Int from 1 through 10. So far, so good. But what kind of tests can I write for

Unit testing IO Int and similar in Haskell

99封情书 提交于 2020-08-19 04:17:42
问题 From Ninety-Nine Haskell Problems: Question 23: Extract a given number of randomly selected elements from a list. This is a partial solution. For simplicity, this code just selects one element from a list. import System.Random (randomRIO) randItem :: [a] -> IO a randItem xs = do i <- randomRIO (0,length xs - 1) return $ xs !! i so randItem [1..10] would return an IO Int that corresponds to (but does not equal) some Int from 1 through 10. So far, so good. But what kind of tests can I write for

Unit testing IO Int and similar in Haskell

妖精的绣舞 提交于 2020-08-19 04:17:08
问题 From Ninety-Nine Haskell Problems: Question 23: Extract a given number of randomly selected elements from a list. This is a partial solution. For simplicity, this code just selects one element from a list. import System.Random (randomRIO) randItem :: [a] -> IO a randItem xs = do i <- randomRIO (0,length xs - 1) return $ xs !! i so randItem [1..10] would return an IO Int that corresponds to (but does not equal) some Int from 1 through 10. So far, so good. But what kind of tests can I write for

See which Typeclasses the Type is an instance of in ghci?

独自空忆成欢 提交于 2020-08-18 08:23:46
问题 Is it possible to see which typeclasses the type implements? Something like: >:typeclasses Int [Num, etc...] 回答1: Use the :info command. Prelude> :info Int data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in GHC.Types instance Bounded Int -- Defined in GHC.Enum instance Enum Int -- Defined in GHC.Enum instance Eq Int -- Defined in GHC.Base instance Integral Int -- Defined in GHC.Real instance Num Int -- Defined in GHC.Num instance Ord Int -- Defined in GHC.Base instance Read Int -- Defined in

图灵完备语言 Turing-Complete Language

独自空忆成欢 提交于 2020-08-14 02:45:55
概述 如果一个计算机语言具有 图灵完备性(Turing Completeness) ,那么这个语言就是 图灵完备语言 (Turing-Complete Language)。 背景 艾伦·图灵 艾伦·麦席森·图灵 (Alan Mathison Turing,1912.6.23 - 1954.6.7), 1 英国数学家、逻辑学家、密码学家和英国首位计算机科学家,被誉为计算机科学和人工智能之父。 2 他对计算机科学的发展有着很高的影响力,他用图灵机提供了算法和计算概念的形式化,图灵机可以被视为通用计算机的模型。 3 他的图灵测试对人工智能的发展,作出了重要的、典型的、具挑战性的和持久的贡献。 4 图灵机 在 1928 年第八届国际数学家大会上,德国数学家希尔伯特(David Hilbert,1862 - 1943)提出了关于数学的三个精辟问题: First, was mathematics complete ...(数学是完备的吗?) Second, was mathematics consistent ...(数学是一致的吗?) And thirdly, was mathematics decidable ?(数学是可判定的吗?) 希尔伯特的第三个问题又被称为判定性问题(Entscheidungsproblem)。为了证否这个命题,1936 年,图灵发表了一篇论文,题为《论可计算数

Folding or concatMap-ing an Aeson Array via lenses

天大地大妈咪最大 提交于 2020-08-10 21:22:38
问题 I've been starting at https://www.stackage.org/haddock/lts-12.1/lens-aeson-1.0.2/Data-Aeson-Lens.html and https://www.stackage.org/haddock/lts-12.1/lens-4.16.1/Control-Lens-Fold.html trying to figure out how to write an expression that allows me to construct something of the following type: import Data.Aeson as A functionIWant :: (Vector A.Value) -> (A.Value -> [a]) -> [a] 回答1: There are two lens functions that are used to "lift" regular Foldable -related functions to the lensy world: folded

Folding or concatMap-ing an Aeson Array via lenses

ぐ巨炮叔叔 提交于 2020-08-10 21:19:48
问题 I've been starting at https://www.stackage.org/haddock/lts-12.1/lens-aeson-1.0.2/Data-Aeson-Lens.html and https://www.stackage.org/haddock/lts-12.1/lens-4.16.1/Control-Lens-Fold.html trying to figure out how to write an expression that allows me to construct something of the following type: import Data.Aeson as A functionIWant :: (Vector A.Value) -> (A.Value -> [a]) -> [a] 回答1: There are two lens functions that are used to "lift" regular Foldable -related functions to the lensy world: folded

Folding or concatMap-ing an Aeson Array via lenses

喜夏-厌秋 提交于 2020-08-10 21:19:09
问题 I've been starting at https://www.stackage.org/haddock/lts-12.1/lens-aeson-1.0.2/Data-Aeson-Lens.html and https://www.stackage.org/haddock/lts-12.1/lens-4.16.1/Control-Lens-Fold.html trying to figure out how to write an expression that allows me to construct something of the following type: import Data.Aeson as A functionIWant :: (Vector A.Value) -> (A.Value -> [a]) -> [a] 回答1: There are two lens functions that are used to "lift" regular Foldable -related functions to the lensy world: folded

Hacker News 简讯 2020-07-30

烈酒焚心 提交于 2020-08-10 06:25:39
最后更新时间: 2020-07-30 22:01 Apple does not keep the 30% commission on a refund - (twitter.com) 苹果不保留退款30%的佣金 得分:751 | 评论:192 Alzheimer's: 'Promising' blood test for early stage of disease - (bbc.co.uk) 阿尔茨海默氏症:早期血液检测的前景 得分:15 | 评论:6 You Want to See My Data? I Thought We Were Friends - (nautil.us) 你想看看我的资料吗?我以为我们是朋友 得分:180 | 评论:46 Researchers pick their favourite ML books - (mentorcruise.com) 研究人员挑选他们最喜欢的ML书籍 得分:41 | 评论:6 Universal Basic Income is Capitalism 2.0 - (timjrobinson.com) 普遍的基本收入是资本主义2.0 得分:766 | 评论:1454 The Haskell Elephant in the Room - (stephendiehl.com) 房间里的哈斯克尔大象 得分:21 | 评论:6