ghc

How to integrate dependency into existing project in Haskell?

落爺英雄遲暮 提交于 2021-01-27 18:41:28
问题 I am currently trying to get started with Haskell because I want to use parts of the code base of Pandoc for a different project. Since I am new to Haskell I need proper IDE features like code completion and jump to definition AND type information and documentation on hover . I chose VSCode with the Haskell extension for the job. Now comes my problem: Pandoc depends on pandoc-types which is an integral part of the code, which I need to understand and modify. But using the ghc-option "

GHC type error which I do not understand

不羁的心 提交于 2021-01-27 07:55:18
问题 I am teaching myself Haskell. I want to write a function that recursively finds the first number that has an integer square root and is smaller than a starting number. It looks like this: findFirstSquare :: Int -> Int findFirstSquare x | x <= 0 = error "This function only works for 1 or above" | fromInteger(floor(sqrt(x))) == (sqrt x) = x | otherwise = intSqrt(x - 1) But GHC complains: No instance for (RealFrac Int) arising from a use of `floor' at ... However, if I type the following into

GHC type error which I do not understand

孤人 提交于 2021-01-27 07:53:02
问题 I am teaching myself Haskell. I want to write a function that recursively finds the first number that has an integer square root and is smaller than a starting number. It looks like this: findFirstSquare :: Int -> Int findFirstSquare x | x <= 0 = error "This function only works for 1 or above" | fromInteger(floor(sqrt(x))) == (sqrt x) = x | otherwise = intSqrt(x - 1) But GHC complains: No instance for (RealFrac Int) arising from a use of `floor' at ... However, if I type the following into

Haskell/GHC: Matching multiple unary constructors with the same pattern

主宰稳场 提交于 2021-01-27 06:53:33
问题 So I was playing around with defining a TrieSet datatype (even though I know I don't need to): module Temp where import Data.Map data TrieSet a = Nonterminal (Data.Map a (TrieSet a)) | Terminal (Data.Map a (TrieSet a)) insert :: Ord a => [a] -> TrieSet a -> TrieSet a insert [] (_ m) = Terminal m insert (a:as) (c m) = c $ insertWith (insert as . flip const) a (insert as $ Nonterminal empty) m When I got an error I've never seen before: % ghc -c Temp.hs Temp.hs:8:11: Parse error in pattern So

Pandoc 'Could not find module …' for installed module

倾然丶 夕夏残阳落幕 提交于 2021-01-27 06:31:36
问题 I'm currently trying to use pandoc (as a Haskell module, not as a program) to convert MediaWiki text to other formats. Let's assume this program: import Text.Pandoc.Readers.MediaWiki main = do print "foo" When using runghc to run it, I get the following error message: pandock.hs:1:8: Could not find module `Text.Pandoc.Readers.MediaWiki' Use -v to see a list of the files searched for. My first assumption was that pandoc was either not installed or incorrectly installed. Therefore I reinstalled

COMPLETE pragma doesn't prevent incomplete-patterns warning

点点圈 提交于 2021-01-27 06:09:31
问题 I made two pattern views for a list-like class. infixr 5 :< pattern (:<) :: Stream s => Token s -> s -> s pattern b :< bs <- (uncons -> Just (b, bs)) where b :< bs = cons b bs pattern Nil :: Stream s => s pattern Nil <- (uncons -> Nothing) where Nil = empty uncons signature: uncons :: (Stream s) => s -> Maybe (Token s, s) . Suppose I also have function that uses these patterns like that: foo (b:<bs) = … foo Nil = … It's obvious in this case that pattern matches are exhaustive, and I would

How are list comprehensions implemented in Haskell?

爱⌒轻易说出口 提交于 2021-01-27 03:51:38
问题 Are list comprehensions simply a language feature? What's the easiest way to fake a list comprehension using pure Haskell? Do you have to use a do block/ >>= to do this or could you use some other method for hacking a list comprehension together? Clarification: By "fake" a list comprehension I mean create a function that takes the same input and produces the same input, i.e. a form for the return values, lists to crunch together, and a predicate or multiple predicates. 回答1: Section 3.11 in

How are list comprehensions implemented in Haskell?

心已入冬 提交于 2021-01-27 03:51:30
问题 Are list comprehensions simply a language feature? What's the easiest way to fake a list comprehension using pure Haskell? Do you have to use a do block/ >>= to do this or could you use some other method for hacking a list comprehension together? Clarification: By "fake" a list comprehension I mean create a function that takes the same input and produces the same input, i.e. a form for the return values, lists to crunch together, and a predicate or multiple predicates. 回答1: Section 3.11 in

How are list comprehensions implemented in Haskell?

二次信任 提交于 2021-01-27 03:51:24
问题 Are list comprehensions simply a language feature? What's the easiest way to fake a list comprehension using pure Haskell? Do you have to use a do block/ >>= to do this or could you use some other method for hacking a list comprehension together? Clarification: By "fake" a list comprehension I mean create a function that takes the same input and produces the same input, i.e. a form for the return values, lists to crunch together, and a predicate or multiple predicates. 回答1: Section 3.11 in

What is the suggested way of setting up Haskell on Archlinux?

眉间皱痕 提交于 2021-01-24 10:46:28
问题 Long story short, I'd like some guidance on what's the (best) way to have Haskell work on Archlinux. By work I mean all, in terms of the ghci command line tool, installing packages I don't have - such as vector-space, which this answer to a question of mine refers to -, and any other thing that could be necessary to a Haskell ostinate learner. Archlinux wikipage on Haskell lists three (alternative?) packages for making Haskell work on the system, namely ghc , cabal-install , and stack . I