haskell

haskell can not construct infinite type

折月煮酒 提交于 2021-02-11 04:25:23
问题 I'm new to haskell. I wrote a simple code. But it does not work. I'm getting this 'can not construct infinite type' error. How does it fix. reverse' list | null list = [] | otherwise = (reverse' (tail list)) : (head list) 回答1: The problem arises from your use of the : operator, which has the type (:) :: a -> [a] -> [a] So it takes an element and a list, and returns a new list with that element prepended on. Where you have reverse' (tail list) : head list -- parentheses removed since they're

十年后将要消失的五种编程语言

本小妞迷上赌 提交于 2021-02-10 19:01:09
点击上方“ Python进击者 ”,选择“ 星标 ”公众号 超级无敌干货每日18:00推送给你!!! 作者 | Program Ace 译者 | 王坤祥 策划 | 小智 本文作者从自己的观点出发,介绍了未来 20 年内可能消失的 5 个编程语言,并给出了具体的原因。最后对想要学习编程的初学者给出了学习建议。 随着时间的流逝,程序员们发现了更新、更简单的工作方式,新的编程语言如雨后春笋般出现,但只有少数编程语言能成为社区的新宠。这种进步的一个副作用是一些古老的编程语言必然会跟历史一样被人们遗忘。如果一个编程语言无法随着时间的推移提升其价值,那么它的用户群终将会流失,并逐渐淡出人们的视线,或者成为更新一代编程语言的基础。 最近,古老的 COBOL 编程语言上了热搜。在 1960 年代和 1970 年代,它曾经是许多美国银行和政府机构的首选的编程语言,但最终被更加简单有效的编程语言所取代。但是,使用 COBOL 构建的系统仍然存在,当一些政府机构发现他们需要通过更新代码来全面改革失业系统时,才发现业内没有几个开发人员可以熟练使用该编程语言。 沧海桑田,COBOL 早已物是人非。我们当前的许多编程语言也注定会有相似的下场。本文中,我们将分析未来 20 内最终会消失的 5 种编程语言。我知道这可能会伤害到那些正在使用这几个编程语言的程序员的内心

unsafePerformIO in threaded applications does not work

泪湿孤枕 提交于 2021-02-10 18:12:47
问题 Below is the source of a sample program: When I run it from ghci both printJob and printJob2 run fine and write ten lines into a text file. But when compiled with -threaded flag, the program writes only one line. I have ghc 7.0.3 on ArchLinux Here's the compile command: ghc -threaded -Wall -O2 -rtsopts -with-rtsopts=-N -o testmvar testmvar.hs What am I am doing wrong ? Why it does not work in threaded mode ? import Control.Concurrent.MVar import Control.Concurrent (forkIO) import Control

Add print in Scotty do block

心已入冬 提交于 2021-02-10 18:10:31
问题 I'm very new to Haskell so sorry in advance if the question is silly, but I was not able to find the solution in google. Let's say that I have this program using the Scotty web framework: responseUserByName :: ActionM () responseUserByName = do name <- param "name" user <- liftAndCatchIO $ getUserByUserName name json user I would like to add a log since it is failing at runtime and I cannot tell why. So my idea was to add some print in the do block to check values. But since the do block has

Random numbers in haskell. And shuffling a list

强颜欢笑 提交于 2021-02-10 14:50:22
问题 i am trying to write a function that when given a list would return a lsit in random order. this is how i thought of doing it(the list is of length 52): generate random number between 1 and 52 take that element of the list. a = [1,2,3..] !! getRandom 52 then recursively call same function.. generate random number between 1 and 51 and call on list with first element we picked removed. (delete a [1,2,3..]) !! getRandom 51 And so on..after puting all elements picked in a list we get same list

Convert List comprehension into recursive call

落爺英雄遲暮 提交于 2021-02-10 12:10:40
问题 sieve [] = [] sieve (a:x) = a : sieve [y| y <- x, y `mod` a > 0] I want to convert this code to recursive implementation or using higher order functions such as map and filter. I can't figure out how do I do this. I have tried this way but it wont seem to work sieve (a:x) = f x : map f xs where f = y `mod` a > 0 回答1: Is this the kind of thing you want? The list comprehension is only being used to filter the list anyway, so we can convert to a form that manually applies a filter. sieve [] = []

Convert List comprehension into recursive call

本秂侑毒 提交于 2021-02-10 12:04:41
问题 sieve [] = [] sieve (a:x) = a : sieve [y| y <- x, y `mod` a > 0] I want to convert this code to recursive implementation or using higher order functions such as map and filter. I can't figure out how do I do this. I have tried this way but it wont seem to work sieve (a:x) = f x : map f xs where f = y `mod` a > 0 回答1: Is this the kind of thing you want? The list comprehension is only being used to filter the list anyway, so we can convert to a form that manually applies a filter. sieve [] = []

functors from partially applied function type

微笑、不失礼 提交于 2021-02-10 10:10:34
问题 there is a quesion in Programming in Haskell that says: Complete the following declaration: instance Functor ((->) a) where Now as Functor Thing has a type definition of: instance Functor Thing where --fmap::(a -> b) -> Thing a -> Thing b I was wondering if this reduction makes sense: instance Functor ((->) a) where -- fmap::(a -> b) -> ((->) a) a -> ((->) a) b -- therefore -- fmap::(a -> b) -> a -> a -> (a -> b) -- therefore -- fmap::b -> b -- update --- I missed brackets, it should have

creating a backward list using recursive data type in Haskell

六月ゝ 毕业季﹏ 提交于 2021-02-10 07:18:30
问题 I am trying to create a backward list using Haskell's recursive types data RevList a = Snoc a (RevList a) | Lin deriving Show mkrevlst [] = Lin mkrevlst (x:xs) = mkrevlst xs Snoc x When I do > mkrevlst [1,2,3] ,the output I am expecting is : ((Lin Snoc 3) Snoc 2) Snoc 1 When I run this I get an error. I am new to Haskell & I am not able to make out where is mistake is. Where am I going wrong? Thank you. 回答1: I'm not sure what this line was supposed to be, but it doesn't make sense as is:

Cabal: missing dependency on foreign C library

只谈情不闲聊 提交于 2021-02-10 06:54:19
问题 I have been trying to install the tensorflow/haskell package on my Windows machine. However, both while installing with stack and cabal, I keep running into this error: Cabal-simple_Z6RU0evB_1.24.2.0_ghc-8.0.2.exe: Missing dependency on a foreign library: * Missing C library: tensorflow This problem can usually be solved by installing the system package that provides this library (you may need the "-dev" version). If the library is already installed but in a non-standard location then you can