ghc

Why cannot top level module be set to main in Hint

做~自己de王妃 提交于 2019-12-11 03:13:06
问题 Why cannot top level module be set to "Main" in Hint (Language.Haskell.Interpreter)? Allow me to demonstrate: module Main where import Language.Haskell.Interpreter import Control.Monad main = do res <- runInterpreter (test "test") case res of Left e -> putStrLn (show e) Right t -> putStrLn (show t) return () test :: String -> Interpreter () test mname = do loadModules [mname ++ ".hs"] setTopLevelModules ["Main"] Will result in: NotAllowed "These modules are not interpreted:\nMain\n" 回答1: As

applying a list of Strings to an arbitrary function

北慕城南 提交于 2019-12-11 02:56:06
问题 I'm trying to write a function which allows you to "apply" a list of Strings to an arbitrary function. Here's what I've got so far: {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, OverlappingInstances, TypeFamilies #-} class Apply a c where apply :: a -> [String] -> c instance (Read a, Apply b c) => Apply (a -> b) c where apply _ [] = error "not enough arguments" apply f (x:xs) = apply (f (read x)) xs instance (a ~ b) => Apply a b where apply f [] = f apply _ (_:_) = error "too many

Understanding how to construct GHC.Generics Rep's and convert back to values

半世苍凉 提交于 2019-12-10 23:23:16
问题 I'm trying to learn about how to use GHC.Generics. A fascinating topic but daunting. While reading through the blog entry 24 Days of GHC Extensions: DeriveGeneric, I learned how to take a value and navigate its Rep . Okay. However, reading the blog entry Building data constructors with GHC Generics which describes the analog of constructing the Rep and converting it back to a value, I got stumped. I've read through a number of other resources, but to no great help. In the blog entry is the

Using custom instance when deriving an instance via GeneralizedNewtypeDeriving

非 Y 不嫁゛ 提交于 2019-12-10 21:38:50
问题 Suppose that we have a typeclass class (A a, B a) => C a where . Using newtype will allow us to clone a data type and then automatically derive the instances via the GeneralizedNewtypeDeriving language extension (See how to write a derivable class? and Handling multiple types with the same internal representation and minimal boilerplate?). QUESTION : Is it possible to get ghc to automatically derive A and C , but to use our own specified implementation of B in deriving C ? For example the

Convert from type `T a` to `T b` without boilerplate

こ雲淡風輕ζ 提交于 2019-12-10 19:46:07
问题 So, I have an AST data type with a large number of cases, which is parameterized by an "annotation" type data Expr a = Plus a Int Int | ... | Times a Int Int I have annotation types S and T , and some function f :: S -> T . I want to take an Expr S and convert it to an Expr T using my conversion f on each S which occurs within an Expr value. Is there a way to do this using SYB or generics and avoid having to pattern match on every case? It seems like the type of thing that this is suited for.

Haskell (ghc) runtime memory usage or what do I do wrong

江枫思渺然 提交于 2019-12-10 18:27:07
问题 I wrote a small program, kind of specialized HTTP server in haskell, which is not much more complex than the code below. What puzzles me is its memory consumption. Say, when I run a test compiled from the enclosed code and make several POST requests containing up to 20Mb body whole program will have VM size of ~800Mb and this sounds odd. And this space is not returned to system if I leave an instance of such program running idle. What does this mean? import System.IO import Network.HTTP

Semantics of show w.r.t. escape characters

瘦欲@ 提交于 2019-12-10 17:35:23
问题 Consider the following examples ( λ> = ghci, $ = shell): λ> writeFile "d" $ show "d" $ cat d "d" λ> writeFile "d" "d" $ cat d d λ> writeFile "backslash" $ show "\\" $ cat backslash "\\" λ> writeFile "backslash" "\\" $ cat backslash \ λ> writeFile "cat" $ show "🐈" -- U+1F408 $ cat cat "\128008" λ> writeFile "cat" "🐈" $ cat cat 🐈 I understand that another way of "\128008" is just another way of representing "🐈" in Haskell source code. My question is: why does the "🐈" example behave like the

How to get haskell code after desugaring arrow syntax?

这一生的挚爱 提交于 2019-12-10 17:07:12
问题 I currently try to solve my problem HXT: Can an input change with the arrow syntax? and therefore and want to see the haskell code after the ghc compiler desugars the Arrow syntax. How can I do this? I already tried -ddump-ds but with this flag I get a horrible long code because also all types are resolved. Is there a way to see the code with just arrow syntax desugaring? 回答1: The original arrow project provided a parser, called arrowp , which is available on Hackage and translates the arrow

How to get the errno from an IOError in haskell?

僤鯓⒐⒋嵵緔 提交于 2019-12-10 16:55:36
问题 I'm on the haskell platform, GHC 6.12.1 as apt-get installed on Debian Squeeze. How can I get the underlying errno out of an IOError, given that I need it on a different thread to where it was originally raised? The reason I need this is because I'm implementing a network protocol which exposes the actual errno value on the wire. Do I need to reconstruct it? 回答1: errno is thread-local in GHC. You'll need to trap the errno in one thread; then send the value down a Chan or other communication

Is there a way to use Djinn to auto-generate Haskell code in Emacs?

。_饼干妹妹 提交于 2019-12-10 16:09:44
问题 Title pretty much says it all. I'm looking for something like this: f :: Int -> Bool -> Int f = _body Djinn can use theorem proving to generate code for such a function by proving that the type is inhabited. I'm wondering, is there an existing way to get this functionality from within Emacs? So instead of writing TemplateHaskell in my code, I just run a command on my code and it inserts the generated code? I have ghc-mod installed, but I'm not very familiar with it. 回答1: Quoting the relevant