ghc

Understanding GHC assembly output

假装没事ソ 提交于 2019-12-09 04:13:05
问题 When compiling a haskell source file using the -S option in GHC the assembly code generated is not clear. There's no clear distinction between which parts of the assembly code belong to which parts of the haskell code. Unlike GCC were each label is named according to the function it corresponds to. Is there a certain convention in these names produced by GHC? How can I relate certain parts in the generated assembly code to their corresponding parts in the haskell code? 回答1: For top level

Haskell: TVar: orElse

会有一股神秘感。 提交于 2019-12-09 03:29:15
问题 Is the "else" part of orElse called when a transaction is retried due to another transaction writing to a TVar it had read, or only when retry is explicitly called? 回答1: If you have orElse a b then b is only run if retry is called explicitly in a . Otherwise orElse would essentially become nondeterministic. (The rerunning of transactions that is done by the STM runtime is transparent and should not effect the outcome of any computation.) 来源: https://stackoverflow.com/questions/10101044

Which dictionary does GHC choose when more than one is in scope?

依然范特西╮ 提交于 2019-12-09 02:54:26
问题 Consider the following example: import Data.Constraint class Bar a where bar :: a -> a foo :: (Bar a) => Dict (Bar a) -> a -> a foo Dict = bar GHC has two choices for the dictionary to use when selecting a Bar instance in foo : it could use the dictionary from the Bar a constraint on foo , or it could use the runtime Dict to get a dictionary. See this question for an example where the dictionaries correspond to different instances. Which dictionary does GHC use, and why is it the "correct"

Strange type inferencе with RankNTypes extension

梦想与她 提交于 2019-12-08 20:16:07
问题 I am trying to experiment with System-F types in Haskell and have implemented Church encoding of natural numbers via type . When loading this code {-# OPTIONS_GHC -Wall #-} {-# LANGUAGE RankNTypes #-} type CNat = forall t . (t -> t) -> (t -> t) c0 :: CNat c0 _ x = x type CPair a b = forall t . (a -> b -> t) -> t cpair :: a -> b -> CPair a b cpair a b f = f a b -- pair3 :: CPair CNat String pair3 = cpair c0 "hello" into ghci 7.8.2 I get a warning: λ: :l test.hs [1 of 1] Compiling Main ( test

How to enable dead code warnings in Haskell (GHC)

喜欢而已 提交于 2019-12-08 16:57:08
问题 Some languages (like Go & Rust) require the programmer to be diligent in removing all dead code from the source. This has benefits in code maintainability and readability, if a bit extreme for some users. How can I enable this feature in Haskell? (Is it possible?) For example, in the following code, I'd like url2 to be flagged as dead code because it isn't used in main . url1 = "http://stackoverflow.com" url2 = "http://stackexchange.com" main = print url1 I saw reference to some compiler

Can I change the stack size limits from within the program?

℡╲_俬逩灬. 提交于 2019-12-08 16:54:03
问题 I can configure the maximum stack size of a GHC compiled Haskell program by passing +RTS -Kn to it, where n is some number. Is there a way to change this setting from within the program? (I’d like to benchmark stack consumption of various functions, and hence try to run it with various limits, catching the StackOverflow exception.) 回答1: Time has answered this with: „No“ 来源: https://stackoverflow.com/questions/19950074/can-i-change-the-stack-size-limits-from-within-the-program

How does the <<loop>> error “work” in detail?

隐身守侯 提交于 2019-12-08 16:51:38
问题 I'm working on this tool where the user can define-and-include in [config files | content text-files | etc] their own "templates" (like mustache etc) and these can reference others so they can induce a loop. Just when I was about to create a "max-loops" setting I realized with runghc the program after a while just quits with farewell message of just <<loop>> . That's actually good enough for me but raises a few ponderations: how does GHC or the runtime actually detect it's stuck in a loop,

Type signature needs a type that isn't exported by the library

我只是一个虾纸丫 提交于 2019-12-08 16:51:12
问题 So I was using the aeson library, and thought it would be very useful to have the following function: v .:! f = liftM (fromMaybe mempty) (v .:? f) When I ask GHCi for the type, I get: (.:!) :: (Monoid r, FromJSON r) => Object -> T.Text -> aeson-0.7.0.6:Data.Aeson.Types.Internal.Parser r However, Parser itself is not actually exported by either Data.Aeson or Data.Aeson.Types . Am I forced to not have a type signature for the function I have defined? Alternatively, if anyone knows a better way

Calling Haskell from c++

浪尽此生 提交于 2019-12-08 16:47:37
问题 I'm trying to call Haskell from c++. I tried to use this explanation; and already asked one question on SO. However, I haven't got any answer so I'd like to reformulate to a Minimal, Complete, and Verifiable example. I'm using Debian and this is what I have (In the same folder): c++: // main.cpp #include <iostream> #include "Hello_stub.h" int main(int argc, char** argv) { hs_init(&argc, &argv); std::cout << "Hello from C++\n"; helloFromHaskell(); hs_exit(); return 0; } Haskell: // hello.hs

Data Promotion Syntax

一曲冷凌霜 提交于 2019-12-08 16:46:10
问题 I recently discovered the Data.Promotion half of singletons. It has loads of type families which allow essentially arbitrary computation at the type level. I have a couple of questions about usage: What is the difference between ($), (%$), ($$), and are they related to :++$ , :.$ , etc? Are these actually infix operators? I was under the impression all infix type constructors had to begin with a : . I'm trying to map a constructor over a list: {-# LANGUAGE DataKinds, TypeOperators, PolyKinds