haskell

Detect infinite loops in a GHC program

泪湿孤枕 提交于 2021-02-10 06:10:59
问题 In this example, action is an infinite loop created by mistake. Is there a way to detect such loops in a GHC program? action bucket manager url = catch (action bucket manager url) (\(e :: HttpException) -> Logger.warn $ "Problems with " ++ url) 回答1: Short answer: no. It certainly isn't possible to notice every infinite loop one could write down; this is famously known as the halting problem and the formal proof that one cannot write a loop-detecting program is so famous that there's even a Dr

Hacker News 简讯 2021-02-10

牧云@^-^@ 提交于 2021-02-10 05:55:11
最后更新时间: 2021-02-10 05:00 Creeping as a Service - (every.to) - [中文翻译版] 作为服务爬行 得分:90 | 评论:11 | 评论翻译 Browser Fuzzing at Mozilla - (hacks.mozilla.org) - [中文翻译版] Mozilla浏览器模糊化 得分:111 | 评论:6 | 评论翻译 Minesweeper automates root cause analysis as a first-line defense against bugs - (fb.com) - [中文翻译版] 扫雷艇自动进行根本原因分析,作为对付虫子的第一道防线 得分:45 | 评论:7 | 评论翻译 Launch HN: SigNoz (YC W21) – Open-source alternative to DataDog - [中文翻译版] 发布HN:SigNoz(ycw21)–DataDog的开源替代品 得分:146 | 评论:47 | 评论翻译 Pattern Matching Accepted for Python - (lwn.net) - [中文翻译版] Python接受的模式匹配 得分:72 | 评论:29 | 评论翻译 Looking at GSM security 30 years later

How to extract the value from a certain position in a matrix in Haskell?

烈酒焚心 提交于 2021-02-10 05:40:30
问题 I have to implement a gameboard for 2048. I declared it: type Board = [[Int]] In order to add a new random value in a random cell I must check the value in that cell, but I don't know how to get the value. I've seen different examples using a monad, but I don't know how to use Monad and I was wondering if there is another way to do this. Can anyone help me with an example? Thanks! 回答1: Well, as for checking the value in a particular cell – that's just list-indexing, you can simply use !! .

Mutually recursive evaluator in Haskell

吃可爱长大的小学妹 提交于 2021-02-10 04:55:29
问题 Update: I've added an answer that describes my final solution (hint: the single Expr data type wasn't sufficient). I'm writing an evaluator for a little expression language, but I'm stuck on the LetRec construct. This is the language: type Var = String type Binds = [(Var, Expr)] data Expr = Var Var | Lam Var Expr | App Expr Expr | Con Int | Sub Expr Expr | If Expr Expr Expr | Let Var Expr Expr | LetRec Binds Expr deriving (Show, Eq) And this this the evaluator so far: data Value = ValInt Int

Create the following list [1, 2, [3, 4], [3, [4, 5]]] in Haskell

亡梦爱人 提交于 2021-02-10 03:10:36
问题 I'm trying to make a list that contains sub lists, like [1, 2, [3, 4], [3, [4, 5]]] . It seems like I should define a new type. I tried: data NestedList a = Int a | List [NestedList a] but I think its wrong, or that I don't know how to use it. I'm very new to Haskell and I'm not sure about the meaning of this expression. Does it mean that it is making a "type" Int with parameter a and a "type" List with parameter [NestedList a] ? The data expression above was taken from the solution to the

What is the correct way to define an already existing (e.g. in Prelude) operator between a user-defined type and an existing type?

我与影子孤独终老i 提交于 2021-02-09 09:22:49
问题 Suppose I have a custom type wrapping an existing type, newtype T = T Int deriving Show and suppose I want to be able to add up T s, and that adding them up should result in adding the wrapped values up; I would do this via instance Num T where (T t1) + (T t2) = T (t1 + t2) -- all other Num's methods = undefined I think we are good so far. Please, tell me if there are major concerns up to this point. Now let's suppose that I want to be able to multiply a T by an Int and that the result should

What is the correct way to define an already existing (e.g. in Prelude) operator between a user-defined type and an existing type?

我只是一个虾纸丫 提交于 2021-02-09 09:20:23
问题 Suppose I have a custom type wrapping an existing type, newtype T = T Int deriving Show and suppose I want to be able to add up T s, and that adding them up should result in adding the wrapped values up; I would do this via instance Num T where (T t1) + (T t2) = T (t1 + t2) -- all other Num's methods = undefined I think we are good so far. Please, tell me if there are major concerns up to this point. Now let's suppose that I want to be able to multiply a T by an Int and that the result should

What is the correct way to define an already existing (e.g. in Prelude) operator between a user-defined type and an existing type?

你。 提交于 2021-02-09 09:16:15
问题 Suppose I have a custom type wrapping an existing type, newtype T = T Int deriving Show and suppose I want to be able to add up T s, and that adding them up should result in adding the wrapped values up; I would do this via instance Num T where (T t1) + (T t2) = T (t1 + t2) -- all other Num's methods = undefined I think we are good so far. Please, tell me if there are major concerns up to this point. Now let's suppose that I want to be able to multiply a T by an Int and that the result should

Haskell implicit conversions

為{幸葍}努か 提交于 2021-02-09 07:00:45
问题 Hello i was looking to using Data.Text.intercalate and from Hackage i do not understand why if the method has the following signature: intercalate :: Text -> [Text] -> Text Why then, does this work T.intercalate "NI!" ["We", "seek", "the", "Holy", "Grail"] "WeNI!seekNI!theNI!HolyNI!Grail" Shouldn't you apply Data.Text.pack it before each element of the list? Source : http://hackage.haskell.org/package/text-1.2.3.1/docs/Data-Text.html In my case i want to pack the following : Input : "{" ,

Resolving Network.HTTP 'user error (https not supported)'

时光总嘲笑我的痴心妄想 提交于 2021-02-09 02:40:26
问题 When running this Haskell program using runghc : import Network.HTTP main = simpleHTTP (getRequest "https://stackoverflow.com") >>= getResponseBody >>= putStrLn I get the error message printso.hs: user error (https not supported) I don't want to switch to unencrypted HTTP -- how can I use Network.HTTP with SSL/TLS? 回答1: You can't do that directly, see for example this post. However you could use Network.HTTP.Conduit from the http-conduit library instead. First install it using cabal install