ghc

Why DuplicateRecordFields cannot have type inference?

为君一笑 提交于 2019-11-28 07:36:55
问题 Related post: How to disambiguate selector function? https://ghc.haskell.org/trac/ghc/wiki/Records/OverloadedRecordFields/DuplicateRecordFields However, we do not infer the type of the argument to determine the datatype, or have any way of deferring the choice to the constraint solver. It's actually annoying that this feature is not implemented. I tried to look up multiple sources but I could not find a reason why they decide not to infer types. Does anyone know a good reason for this? Is it

Preferred method for viewing code generated by Template Haskell

吃可爱长大的小学妹 提交于 2019-11-28 06:12:22
As you know, Template Haskell is used to generate various kinds of AST splices programmatically at compile-time. However, a splice can often be very opaque, and it is often difficult to discern what a splice actually generates. If you run the Q monad for a splice, and the splice is well-typed, you get a show able representation of the generated piece of AST, but this representation can be very difficult to understand, because of its unstructured layout. What is the preferred method for converting a piece of TH-generated AST into something akin to normal Haskell code, so that the code can be

How to compile Haskell to a static library?

 ̄綄美尐妖づ 提交于 2019-11-28 04:57:42
Hey, I'm learning Haskell and I'm interested in using it to make static libraries for using in Python and probably C. After some googling I found out how to get GHC to output a shared object, but it dynamically depends on GHC`s libraries. The resulting ELF from compiling in GHC is dynamically dependand only on C libs and it's a bit under a MB in size - it has been statically linked with GHC`s libs. How and if can this be achieved for shared objects? Example of current state: $ ghc --make -dynamic -shared -fPIC foo.hs -o libfoo.so $ ldd libfoo.so linux-vdso.so.1 => (0x00007fff125ff000)

Understanding this definition of HList

随声附和 提交于 2019-11-28 04:42:59
问题 I'm relatively new to Haskell, and I'm trying to understand one of the definitions of HList. data instance HList '[] = HNil newtype instance HList (x ': xs) = HCons1 (x, HList xs) pattern HCons x xs = HCons1 (x, xs) I have a couple specific questions: What is the '[] and (x ': xs) syntax I'm seeing? It almost looks like it's pattern matching on variadic type parameters, but I have never seen this syntax before, nor am I familiar with variadic type parameters in Haskell. I would guess this is

Compiling to GHC Core

亡梦爱人 提交于 2019-11-28 04:06:40
问题 I would like to create a frontend for a simple language that would produce GHC Core. I would like to then take this output and run it through the normal GHC pipeline. According to this page, it is not directly possible from the ghc command. I am wondering if there is any way to do it. I am ideally expecting a few function calls to the ghc-api but I am also open to any suggestions that include (not-so-extensive) hacking in the source of GHC. Any pointers would help! 回答1: There's still no way

When is -XAllowAmbiguousTypes appropriate?

本秂侑毒 提交于 2019-11-28 03:30:26
I've recently posted a question about syntactic-2.0 regarding the definition of share . I've had this working in GHC 7.6 : {-# LANGUAGE GADTs, TypeOperators, FlexibleContexts #-} import Data.Syntactic import Data.Syntactic.Sugar.BindingT data Let a where Let :: Let (a :-> (a -> b) :-> Full b) share :: (Let :<: sup, sup ~ Domain b, sup ~ Domain a, Syntactic a, Syntactic b, Syntactic (a -> b), SyntacticN (a -> (a -> b) -> b) fi) => a -> (a -> b) -> b share = sugarSym Let However, GHC 7.8 wants -XAllowAmbiguousTypes to compile with that signature. Alternatively, I can replace the fi with (ASTF

Using cabal with multiple GHC versions

孤街醉人 提交于 2019-11-28 02:39:50
问题 I got both ghc6 and ghc7 on my desktop. To install new packages (for the specific ghc version), I use cabal with the flag --with-compiler=<ghc-dir> to specify for which ghc i want the package installed. I do cabal update before installing any new package. But how to I specify for which ghc I want the update? I mean, there is no --with-compiler flag as with cabal install . I would think that just like I use ghc-pkg7 for ghc7, there would be cabal7 . Apart from the cabal install command which I

Why does this function that uses a scoped type variable in a where clause not typecheck?

随声附和 提交于 2019-11-28 01:10:24
I have a function that has a value defined in a where clause, and I want to give it an explicit type annotation. The annotation needs to use a type variable from the top-level function, so it was my understanding that I needed to use ScopedTypeVariables . Here is a minimal reduction of the problem: {-# LANGUAGE ScopedTypeVariables #-} import Control.Monad.Trans.Except import Data.Functor.Identity f :: ExceptT String Identity a -> Maybe a f m = Nothing where x :: Identity (Either String a) x = runExceptT m This code does not typecheck. It fails with the following error message: Couldn't match

How does GHCi pick names for type variables?

纵饮孤独 提交于 2019-11-27 23:38:38
问题 When using the interactive GHC interpreter, it's possible to ask for the inferred type of an expression: Prelude> :t map map :: (a -> b) -> [a] -> [b] It seems that it takes the names of the type variables from the signature since map is defined as map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs in the Prelude. That makes a lot of sense! My question is: how are type variable names picked when there is no signature given? An example would be Prelude> :t map fst map

Using Haskell to output a UTF-8-encoded ByteString

微笑、不失礼 提交于 2019-11-27 21:37:04
问题 I'm going out of my mind trying to simply output UTF-8-encoded data to the console. I've managed to accomplish this using String , but now I'd like to do the same with ByteString . Is there a nice and fast way to do this? This is what I've got so far, and it's not working: import Prelude hiding (putStr) import Data.ByteString.Char8 (putStr, pack) main :: IO () main = putStr $ pack "čušpajž日本語" It prints out uapaj~�,� , ugh. I'd like an answer for the newest GHC 6.12.1 best, although I'd like