haskell

Parsing html in haskell

别说谁变了你拦得住时间么 提交于 2020-01-02 05:14:09
问题 I'm trying to parse the a links from the main part ( <article> ) of a blog post. I have adapted what I found on FPComplete but nothing is printed out. (The code does not work as far as I can see as running it on the online IDE and with the Bing target also produces no links.) In GHCI I can simulate the first line of parseAF and that gets me a large record, which I take to be correct. But cursor $// findNodes &| extractData returns [] I've tried regex but that wasn't happy trying to find such

Why ZipList is not the default Applicative Instance for List

做~自己de王妃 提交于 2020-01-02 05:02:56
问题 I am currently learning Applicatives in Haskell. If I am not wrong, there are two different Applicative instances for Lists, ( List and ZipList - the second being defined as a newtype wrapping a List value). The ZipList applicative instances seems more intuitive for me. It might be a dumb question, but is there a specific reason ZipList is not the default Applicative instance for Lists. pure (+) <*> [1,2,3] <*> [4,5,6] -- [5,6,7,6,7,8,7,8,9] pure (+) <*> ZipList [1,2,3] <*> ZipList [4,5,6] --

What purpose does the complexity of `Except` serve in Haskell?

巧了我就是萌 提交于 2020-01-02 04:56:31
问题 I understand (I think) that there is a close relationship between Either and Except in Haskell, and that it is easy to convert from one to the other. But I'm a bit confused about best practices for handling errors in Haskell and under what circumstances and scenarios I would choose one over the other. For example, in the example provided in Control.Monad.Except , Either is used in the definition type LengthMonad = Either LengthError so that calculateLength "abc" is Right 3 If instead one were

Logical AND strictness with IO monad

一世执手 提交于 2020-01-02 04:51:10
问题 I am trying to write a simple program in Haskell. It should basically run two shell commands in parallel. Here is the code: import System.Cmd import System.Exit import Control.Monad exitCodeToBool ExitSuccess = True exitCodeToBool (ExitFailure _) = False run :: String -> IO Bool run = (fmap exitCodeToBool) . system main = liftM2 (&&) (run "foo") (run "bar") But command "foo" returns ExitFailure and I expect "bar" never to run. This is not the case! They both run and both show errors on the

Cannot compute minimal length of a parser - uu-parsinglib in Haskell

China☆狼群 提交于 2020-01-02 04:42:08
问题 Lets see the code snippet: pSegmentBegin p i = pIndentExact i *> ((:) <$> p i <*> ((pEOL *> pSegment p i) <|> pure [])) if I change this code in my parser to: pSegmentBegin p i = do pIndentExact i ((:) <$> p i <*> ((pEOL *> pSegment p i) <|> pure [])) I've got an error: canot compute minmal length of a parser due to occurrence of a moadic bind, use addLength to override I thought the above parser should behave the same way. Why this error can occur? EDIT The above example is very simple (to

why pipes defines inner functions

天大地大妈咪最大 提交于 2020-01-02 04:36:04
问题 I'm looking at the pipes library source code and for instance in the Core module I don't understand why the author is all over the place using the pattern of defining functions like that: runEffect = go where go p = ... Or: pull = go where go a' = ... Or: reflect = go where go p = ... Is this some trick to enable some optimizations? I find it ugly, if it's some optimization trick I really wish the compiler could do it without things like that. But maybe there's another reason? 回答1: GHC will

Retrieve a list of all imports in a Haskell project

谁说我不能喝 提交于 2020-01-02 04:30:12
问题 So, my ultimate goal is to evaluate the accuracy of the dependencies in a cabal file, by ensuring that all the entities that the project imports exist in the versions that it claims to work with. A good start would be finding a list of all the imported entities that a single source file uses, optionally with information as to where they come from. I'm willing to ignore the case of class instances for the moment, since detecting their use is not so straightforward. Ideal answer would be a

Test if Haskell variable matches user-defined data type option

梦想与她 提交于 2020-01-02 04:29:11
问题 So I have a data type sort of like: data Token = NUM Int | ID String | EOF and I have a function sort of like: doStuff list = let (token, rest) = getToken list in .... So what I want to do in the ... part is test if the token I got is a NUM or INT or EOF . I can say token==EOF to test for that case, but I can't figure out a way to test if the token is a NUM or INT using a conditional, since token==(NUM n) and token==NUM both result in errors. I know that I could write a helper function to do

Why can ghci see non-exported types and constructors? How can I fix it?

南楼画角 提交于 2020-01-02 04:04:14
问题 I am a novice in Haskell. Here's some simple code: module Src ( -- The 'Answer' type isn't exported Shape(Circle), -- i.e 'Rectangle' data constructor isn't exported Point(..), area, nudge ) where data Answer = Yes | No deriving (Show) data Point = Point Float Float deriving (Show) data Shape = Circle Point Float | Rectangle Point Point deriving (Show) area :: Shape -> Float area (Circle _ r) = pi * r ^ 2 area (Rectangle (Point x1 y1) (Point x2 y2)) = (abs $ x2 - x1) * (abs $ y2 - y1) nudge:

How to get the process ID of a created process in Haskell?

十年热恋 提交于 2020-01-02 03:56:05
问题 Maybe I'm just missing something obvious in the System.Process API (http://hackage.haskell.org/package/process), but it doesn't appear to support getting the raw PID of a process created. The API usually returns a ProcessHandle which can be used easily enough, but this doesn't appear to fulfill a deployment need I have. I have a case where I want to spawn a long-running process, log the PID it's using, and be able to automatically come back at a later time (days, weeks, months) and kill the