ghc

Haskell lexical layout rule implementation

天大地大妈咪最大 提交于 2020-01-03 11:13:09
问题 I have been working on a pet language, which has Haskell-like syntax. One of the neat things which Haskell does, which I have been trying to replicate, is its insertion of {, } and ; tokens based on code layout, before the parsing step. I found http://www.haskell.org/onlinereport/syntax-iso.html, which includes a specification of how to implement the layout program, and have made a version of it (modified, of course, for my (much simpler) language). Unfortunately, I am getting an incorrect

Haskell lexical layout rule implementation

戏子无情 提交于 2020-01-03 11:12:12
问题 I have been working on a pet language, which has Haskell-like syntax. One of the neat things which Haskell does, which I have been trying to replicate, is its insertion of {, } and ; tokens based on code layout, before the parsing step. I found http://www.haskell.org/onlinereport/syntax-iso.html, which includes a specification of how to implement the layout program, and have made a version of it (modified, of course, for my (much simpler) language). Unfortunately, I am getting an incorrect

How can I detect if GHC is set to generate 32bit or 64bit code by default?

醉酒当歌 提交于 2020-01-03 09:03:11
问题 I have the following bits in my makefile: GLFW_FLAG := -m32 -O2 -Iglfw/include -Iglfw/lib -Iglfw/lib/cocoa $(CFLAGS) ... $(BUILD_DIR)/%.o : %.c $(CC) -c $(GLFW_FLAG) $< -o $@ $(BUILD_DIR)/%.o : %.m $(CC) -c $(GLFW_FLAG) $< -o $@ The -m32 instructs GCC to generate 32bit code. It's there because on some configurations GHC is set to build 32bit code but GCC's default is sometimes 64bit. I would like to generalize this so that it autodetects whether GHC is building 32bit or 64bit code and then

What is the rule of the order of multiple type variables in haskell?

[亡魂溺海] 提交于 2020-01-03 07:17:13
问题 For example, ParsecT has multiple type variables in its definition. newtype ParsecT s u m a = ParsecT {unParser :: forall b . State s u -> (a -> State s u -> ParseError -> m b) -> (ParseError -> m b) -> (a -> State s u -> ParseError -> m b) -> (ParseError -> m b) -> m b } Can we do it like this ? newtype ParsecT m a s u -- Only the order of s u m a is changed to m a s u. = ParsecT {unParser :: forall b . State s u -> (a -> State s u -> ParseError -> m b) -> (ParseError -> m b) -> (a -> State

Why does `peek` with a polymorphic Ptr return GHC.Prim.Any when used with a bind?

老子叫甜甜 提交于 2020-01-02 08:38:25
问题 Using the low-level GNU Science Library bindings Bindings.Gsl.RandomNumberGeneration, I'm running into this odd type behavior in GHCi where binding changes return type from a peek into GHC.Prim.Any . I'm trying to understand why since I can't use the c'rng_alloc unless I retain the type of pointer to an rng . For eample: λ> :t c'gsl_rng_alloc c'gsl_rng_alloc :: Ptr C'gsl_rng_type -> IO (Ptr C'gsl_rng) λ> :t p'gsl_rng_mt19937 p'gsl_rng_mt19937 :: Ptr (Ptr gsl_rng_type) λ> :t peek p'gsl_rng

Why can't cabal build mighttpd2 dynamically?

£可爱£侵袭症+ 提交于 2020-01-02 08:12:09
问题 GHC is too slow when it links my executable statically, so I want to test using "-dynamic" options. The following two commands cause the same error although cabal install mighttpd2 is ok. $cabal install --ghc-options=-dynamic mighttpd2 $cabal install --enable-executable-dynamic mighttpd2 Linking dist/build/mkindex/mkindex ... Preprocessing executable 'mightyctl' for mighttpd2-2.7.1... Process.hs:11:8: Could not find module `Data.Conduit.Process' Perhaps you haven't installed the "dyn"

Why can't cabal build mighttpd2 dynamically?

核能气质少年 提交于 2020-01-02 08:12:07
问题 GHC is too slow when it links my executable statically, so I want to test using "-dynamic" options. The following two commands cause the same error although cabal install mighttpd2 is ok. $cabal install --ghc-options=-dynamic mighttpd2 $cabal install --enable-executable-dynamic mighttpd2 Linking dist/build/mkindex/mkindex ... Preprocessing executable 'mightyctl' for mighttpd2-2.7.1... Process.hs:11:8: Could not find module `Data.Conduit.Process' Perhaps you haven't installed the "dyn"

GHC Haskell performance of IPv4 address rendering

这一生的挚爱 提交于 2020-01-02 07:27:29
问题 I recently built a library for handling IPv4 address in haskell. I have written two functions to render an IPv4 address to Text and I am surprised that the naive approach outperforms the approach that I actually thought about. Here are the relevant pieces. First, there is the definition of IPv4: newtype IPv4 = IPv4 { getIPv4 :: Word32 } Next we have the IP address renderer that I expected to perform well: toDotDecimalText :: IPv4 -> Text toDotDecimalText = LText.toStrict . TBuilder.toLazyText

Replace record projection function with lenses

你说的曾经没有我的故事 提交于 2020-01-02 05:38:12
问题 Almost every time I make a record, I find myself adding makeLenses ''Record (from lens) immediately afterwards, and I never end up actually using the projection functions that the record gives me. In fact, looking at what makeLenses produces (with the GHC -ddump-splices flag), it looks like not even it uses those projection functions, except to choose a name for the lenses it produces. Is there some way, either through TemplateHaskell , or through a preprocessor, or frankly any other magic,

why pipes defines inner functions

天大地大妈咪最大 提交于 2020-01-02 04:36:04
问题 I'm looking at the pipes library source code and for instance in the Core module I don't understand why the author is all over the place using the pattern of defining functions like that: runEffect = go where go p = ... Or: pull = go where go a' = ... Or: reflect = go where go p = ... Is this some trick to enable some optimizations? I find it ugly, if it's some optimization trick I really wish the compiler could do it without things like that. But maybe there's another reason? 回答1: GHC will