ghc

Universal type tranformer in Haskell

不羁的心 提交于 2019-12-19 09:27:07
问题 Logically, it's possible to define universal transformation function, that can transform from any type to any type. The possible way is: {-#LANGUAGE MultiParamTypeClasses #-} {-#LANGUAGE FlexibleInstances #-} class FromTo a b where fromTo:: a->b instance FromTo a a where fromTo = id instance FromTo Int Double where fromTo = fromIntegral instance FromTo Int Float where fromTo = fromIntegral instance FromTo Integer Double where fromTo = fromIntegral instance FromTo Integer Float where fromTo =

Statically enforcing that two objects were created from the same (Int) “seed”

痞子三分冷 提交于 2019-12-19 08:58:29
问题 In a library I'm working on, I have an API similar to the following: data Collection a = Collection Seed {-etc...-} type Seed = Int newCollection :: Seed -> IO (Collection a) newCollection = undefined insert :: a -> Collection a -> IO () -- ...and other mutable set-like functions insert = undefined mergeCollections :: Collection a -> Collection a -> IO (Collection a) mergeCollections (Collection s0 {-etc...-}) (Collection s1 {-etc...-}) | s0 /= s1 = error "This is invalid; how can we make it

In Haskell, what does it mean if a binding “shadows an existing binding”?

孤人 提交于 2019-12-19 05:49:35
问题 I'm getting a warning from GHC when I compile: Warning: This binding for 'pats' shadows an existing binding in the definition of 'match_ignore_ancs' Here's the function: match_ignore_ancs (TextPat _ c) (Text t) = c t match_ignore_ancs (TextPat _ _) (Element _ _ _) = False match_ignore_ancs (ElemPat _ _ _) (Text t) = False match_ignore_ancs (ElemPat _ c pats) (Element t avs xs) = c t avs && match_pats pats xs Any idea what this means and how I can fix it? Cheers. 回答1: It means that you have a

In Haskell, what does it mean if a binding “shadows an existing binding”?

自作多情 提交于 2019-12-19 05:49:33
问题 I'm getting a warning from GHC when I compile: Warning: This binding for 'pats' shadows an existing binding in the definition of 'match_ignore_ancs' Here's the function: match_ignore_ancs (TextPat _ c) (Text t) = c t match_ignore_ancs (TextPat _ _) (Element _ _ _) = False match_ignore_ancs (ElemPat _ _ _) (Text t) = False match_ignore_ancs (ElemPat _ c pats) (Element t avs xs) = c t avs && match_pats pats xs Any idea what this means and how I can fix it? Cheers. 回答1: It means that you have a

Haskell ghc compiling/linking error, not creating executable. (linux)

耗尽温柔 提交于 2019-12-19 05:08:58
问题 I wrote a basic hello world program in haskel and tried to compile it with: ghc filename.hs. It produces .hi and .o files but no executable and displays this error in the linker: marox@IT-marox:~/Marox$ ghc tupel.hs Linking tupel ... /usr/bin/ld: --hash-size=31: unknown option /usr/bin/ld: use the --help option for usage information collect2: ld returned 1 exit status Googling didn't return any useful information. I am on ubuntu 12.04. How can I fix this? 回答1: Have you binutils-gold installed

GHC package conflicts

﹥>﹥吖頭↗ 提交于 2019-12-19 02:47:10
问题 I'm trying to compile the following code with GHC: module Test where import Maybe import Prelude hiding (null) import System.IO null = () main :: IO () main = putStrLn "Hello, world!" If I just run ghc Test.hs , I get: Could not find module `Maybe' It is a member of the hidden package `haskell98-2.0.0.1'. So I try ghc -package haskell98 Test.hs : Ambiguous module name `Prelude': it was found in multiple packages: base haskell98-2.0.0.1 It doesn't seem right, but I try ghc -package haskell98

How does IncoherentInstances work?

為{幸葍}努か 提交于 2019-12-18 10:48:23
问题 Playing around with some code: {-# LANGUAGE FlexibleInstances, OverlappingInstances #-} class Arity f where arity :: f -> Int instance Arity x where arity _ = 0 instance Arity f => Arity ((->) a f) where arity f = 1 + arity (f undefined) Without IncoherentInstances : ghci> arity foldr blah blah ambiguous blah blah possible fix blah ghci> arity (foldr :: (a -> Int -> Int) -> Int -> [a] -> Int) 3 ghci> let f x y = 3 in arity f 2 ghci> arity $ \x y -> 3 2 If we add IncoherentInstances to the

Why does this Haskell code run slower with -O?

两盒软妹~` 提交于 2019-12-18 10:44:08
问题 This piece of Haskell code runs much slower with -O , but -O should be non-dangerous. Can anyone tell me what happened? If it matters, it is an attempt to solve this problem, and it uses binary search and persistent segment tree: import Control.Monad import Data.Array data Node = Leaf Int -- value | Branch Int Node Node -- sum, left child, right child type NodeArray = Array Int Node -- create an empty node with range [l, r) create :: Int -> Int -> Node create l r | l + 1 == r = Leaf 0 |

Acid-state: MonadState instance for Update

随声附和 提交于 2019-12-18 08:45:33
问题 I'm trying acid-state . The documentation states that Update st is an instance of MonadState st . I tried different things, but my compiler doesn't want to see that :( I tried the HelloWorld.hs from examples, but got the same issue: HelloWorld.hs:26:7: No instance for (MonadState HelloWorldState (Update HelloWorldState)) arising from a use of `put' Possible fix: add an instance declaration for (MonadState HelloWorldState (Update HelloWorldState)) In the expression: put (HelloWorldState

Acid-state: MonadState instance for Update

て烟熏妆下的殇ゞ 提交于 2019-12-18 08:45:10
问题 I'm trying acid-state . The documentation states that Update st is an instance of MonadState st . I tried different things, but my compiler doesn't want to see that :( I tried the HelloWorld.hs from examples, but got the same issue: HelloWorld.hs:26:7: No instance for (MonadState HelloWorldState (Update HelloWorldState)) arising from a use of `put' Possible fix: add an instance declaration for (MonadState HelloWorldState (Update HelloWorldState)) In the expression: put (HelloWorldState