ghc

Is it possible to produce stand alone haskell executable

烂漫一生 提交于 2019-11-30 03:28:11
问题 Is there any way to produce stand alone haskell executable to run on different linux machines assuming the architecture is similar? Sorry I should have been clearer. The other machines might not have ghc installed on them - a bit like pyinstaller for python is what I was looking for? 回答1: You can use the flags -static -optl-pthread -optl-static to avoid dynamically linked dependencies when compiling a Haskell project. This should help you run the compiled executable on two linux machines that

Installing ghc binaries on Linux (can't find libgmp.so)

邮差的信 提交于 2019-11-30 01:33:21
I am trying to install the Haskell Platform on Linux for the first time (I'm also a fairly new Linux user). The victim system is a fresh Red Hat system. And everything involved here should be 64 bit. The directions at the platform website [1] indicate that I need a ghc7.0.3 to boostrap things. They provide a link to a generic binary of ghc-7.0.3 to do this. I fetched this and ran $ ./configure ... $ make install ... as per the directions without incident (it is a binary, so no compilation needed) However, when I tried to run ghci I get the output. $ ghci GHCi, version 7.0.3: http://www.haskell

Haskell: getting the static type of an expression

♀尐吖头ヾ 提交于 2019-11-30 01:27:54
I'm looking for a function that does what the GHCi :type command does. Ideally, it would have a signature something like getStaticType :: a -> String a = getStaticType (1+2) -- a = "(Num t) => t" b = getStaticType zipWith -- b = "(a -> b -> c) -> [a] -> [b] -> [c]" (Note: this has nothing to do with Data.Dynamic. I just want the static type inferred from the compiler. In fact the function wouldn't need a runtime implementation at all, as all calls to it could be inlined as constants at compile time. I'm assuming it exists somewhere, since GHCi can do it) You can do it like this: import Data

Why were type classes difficult to implement?

折月煮酒 提交于 2019-11-30 01:15:23
On slide 30/78 of this presentation, Simon suggests that implementation of type classes was a "despair" at the beginning. Is anybody aware why that was? I guess I'm one of the few people who have first hand experience of why it was hard, since I implemented it in hbc when there was no prior art. So what was clear from the Wadler&Blott paper was that type checking was an extension of Hindley-Milner type checking and that at runtime you should be passing dictionaries around. From that to an actual implementation is a rather big step. A good way to understand the difficulty is to actually

How does IncoherentInstances work?

左心房为你撑大大i 提交于 2019-11-29 23:41:14
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 list of pragmas, then it can handle foldr without needing a monomorphic type signature, but it gets the

Difference between print and putStrLn in Haskell

早过忘川 提交于 2019-11-29 23:11:54
I am confused. I tried to use print , but I know people apply putStrLn . What are the real differences between them? print $ function putStrLn $ function Chris Taylor The function putStrLn takes a String and displays it to the screen, followed by a newline character ( put a Str ing followed by a new L i n e). Because it only works with String s, a common idiom is to take any object, convert it to a String , and then apply putStrLn to display it. The generic way to convert an object to a String is with the show function, so your code would end up with a lot of putStrLn (show 1) putStrLn (show

Can a `ST`-like monad be executed purely (without the `ST` library)?

放肆的年华 提交于 2019-11-29 22:55:52
This post is literate Haskell. Just put in a file like "pad.lhs" and ghci will be able to run it. > {-# LANGUAGE GADTs, Rank2Types #-} > import Control.Monad > import Control.Monad.ST > import Data.STRef Okay, so I was able to figure how to represent the ST monad in pure code. First we start with our reference type. Its specific value is not really important. The most important thing is that PT s a should not be isomorphic to any other type forall s . (In particular, it should be isomorphic to neither () nor Void .) > newtype PTRef s a = Ref {unref :: s a} -- This is defined liked this to make

Why does this Haskell code run slower with -O?

梦想的初衷 提交于 2019-11-29 22:44:49
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 | otherwise = Branch 0 (create l m) (create m r) where m = (l + r) `div` 2 -- Get the sum in range [0, r).

How are lists implemented in Haskell (GHC)?

删除回忆录丶 提交于 2019-11-29 22:43:39
I was just curious about some exact implementation details of lists in Haskell (GHC-specific answers are fine)--are they naive linked lists, or do they have any special optimizations? More specifically: Do length and (!!) (for instance) have to iterate through the list? If so, are their values cached in any way (i.e., if I call length twice, will it have to iterate both times)? Does access to the back of the list involve iterating through the whole list? Are infinite lists and list comprehensions memoized? (i.e., for fib = 1:1:zipWith (+) fib (tail fib) , will each value be computed

Boilerplate-free annotation of ASTs in Haskell?

独自空忆成欢 提交于 2019-11-29 22:19:03
I've been fiddling around with the Elm compiler, which is written in Haskell. I'd like to start implementing some optimizations for it, and part of this involves traversing the AST and adding "annotation" to certain nodes, such as tail-calls, etc. I know I can use SYB or uniplate to do the traversal, but I'm wondering if there's a boilerplate-free way to deal with the types. So, suppose we have a bunch of algebraic types for our AST: data Expr = PlusExpr Expr Expr ... data Def = TypeAlias String [String] Type ... If I were writing the boilerplate, I'd make new types like this: data