ghc

Why is there no `-XDeriveApplicative` extension?

Deadly 提交于 2019-12-01 15:05:59
GHC has several useful language extensions for mechanically deriving various common Haskell typeclasses ( -XDeriveFunctor , -XDeriveFoldable , -XDeriveTraversable ). It seems that Applicative is another class which is often needed and frequently easily derived. For a simple record containing slots of type a , e.g., data SimpleRecord a = Simple a a a the Applicative instance is trivially derived, instance Applicative SimpleRecord where pure x = Simple x x x Simple a1 b1 c1 <*> Simple a2 b2 c2 = Simple (a1 a2) (b1 b2) (c1 c2) Even in the slightly harder case where some a values are buried in

Liberal coverage condition introduced in GHC 7.7 breaks code valid in GHC 7.6

不羁岁月 提交于 2019-12-01 14:39:53
问题 The idea I'm writing a DSL, which compiles to Haskell. Users of this language can define own immutable data structures and associated functions. By associated function I mean a function, which belongs to a data structure. For example, user can write (in "pythonic" pseudocode): data Vector a: x,y,z :: a def method1(self, x): return x (which is equivalent to the following code, but shows also, that associated functions beheva like type classes with open world assumption): data Vector a: x,y,z :

Python-“is”-like equality operator for Haskell/GHC

人盡茶涼 提交于 2019-12-01 14:15:11
问题 Is there a GHC-specific "unsafe" extension to ask whether two Haskell references point to the same location? I'm aware this can break referential transparency if not used properly. But there should be little harm (unless I'm missing something), if it is used very careful, as a means for optimizations by short-cutting recursive (or expensive) data traversal, e.g. for implementing an optimized Eq instance, e.g.: instance Eq ComplexTree where a == b = (a `unsafeSameRef` b) || (a `deepCompare` b)

Let-renaming function breaks code

喜欢而已 提交于 2019-12-01 13:55:49
问题 While iterating my code towards a correct version, I came across the following curiosity: {-# LANGUAGE RankNTypes #-} module Foo where import Data.Vector.Generic.Mutable as M import Control.Monad.Primitive -- an in-place vector function with dimension data DimFun v m r = DimFun Int (v (PrimState m) r -> m ()) eval :: (PrimMonad m, MVector v r) => DimFun v m r -> v (PrimState m) r -> m () eval = error "" iterateFunc :: (PrimMonad m, MVector v r) => (forall v' . (MVector v' r) => DimFun v' m r)

'idiomatic' Haskell type inequality

帅比萌擦擦* 提交于 2019-12-01 09:20:42
(edited from previous question where I thought code below doesn't work) I wish to implement a haskell function f that has a restriction such that its 2 parameters must not have the same type. I have used the following code: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances, FlexibleInstances, FlexibleContexts, TypeFamilies, IncoherentInstances #-} data HTrue = HTrue data HFalse = HFalse class HEq x y b | x y -> b instance (b ~ HTrue) => HEq x x b instance (b ~ HFalse) => HEq x y b g :: (HEq a b HFalse) => a -> b -> () g x y = () Now the function g only accepts a

Universal type tranformer in Haskell

一笑奈何 提交于 2019-12-01 08:08:37
Logically, it's possible to define universal transformation function, that can transform from any type to any type. The possible way is: {-#LANGUAGE MultiParamTypeClasses #-} {-#LANGUAGE FlexibleInstances #-} class FromTo a b where fromTo:: a->b instance FromTo a a where fromTo = id instance FromTo Int Double where fromTo = fromIntegral instance FromTo Int Float where fromTo = fromIntegral instance FromTo Integer Double where fromTo = fromIntegral instance FromTo Integer Float where fromTo = fromIntegral instance FromTo Double Int where fromTo = round instance FromTo Double Integer where

'idiomatic' Haskell type inequality

懵懂的女人 提交于 2019-12-01 07:38:11
问题 (edited from previous question where I thought code below doesn't work) I wish to implement a haskell function f that has a restriction such that its 2 parameters must not have the same type. I have used the following code: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances, FlexibleInstances, FlexibleContexts, TypeFamilies, IncoherentInstances #-} data HTrue = HTrue data HFalse = HFalse class HEq x y b | x y -> b instance (b ~ HTrue) => HEq x x b instance (b ~

What does Core Haskell applying types to functions mean?

♀尐吖头ヾ 提交于 2019-12-01 05:47:41
问题 I wrote a custom pretty printer for Core Haskell in order to better study Core's structure. The gist of this pretty printer is that it takes a CoreModule and includes data constructors in the output, which the default Outputable implementation does not seem to do. Here is the code of the module that I am running the pretty printer on: module Bar2 where add :: Int -> Int -> Int add a b = a + b add2 a b = a + b Here is the pretty printer output: ------------------------------- Module Metadata -

Cannot get cabal to find the mpi library for haskell-mpi on Windows [closed]

﹥>﹥吖頭↗ 提交于 2019-12-01 04:14:44
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . PROBLEM IS SOLVED! Follow the instructions Dons posted here Open your environment variables (My Computer -> Properties (in the context menu) -> Advanced)

In Haskell, what does it mean if a binding “shadows an existing binding”?

一世执手 提交于 2019-12-01 03:51:01
I'm getting a warning from GHC when I compile: Warning: This binding for 'pats' shadows an existing binding in the definition of 'match_ignore_ancs' Here's the function: match_ignore_ancs (TextPat _ c) (Text t) = c t match_ignore_ancs (TextPat _ _) (Element _ _ _) = False match_ignore_ancs (ElemPat _ _ _) (Text t) = False match_ignore_ancs (ElemPat _ c pats) (Element t avs xs) = c t avs && match_pats pats xs Any idea what this means and how I can fix it? Cheers. It means that you have a symbol pats defined somewhere else in your program or imported from some library module, and it's visible in