### [Haskell-cafe] `typeof' is not a (visible) method of class `Typeable' ?

Hi All, While I was trying to declare Language.Haskell.TH.Exp as an instance of Typeable, ghci 6.4 yields this error. It does not allow me to define an instance of typeof. Does anybody know what should be the right way of doing this? Thanks. -W-M- @ @ | \_/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

### ghci bug with template Haskell

Prelude let x = 1 Prelude $([|x|]) ghc.exe: panic! (the `impossible' happened, GHC version 6.2.2): nameModule x {- v a6XY -} Please report it as a compiler bug to glasgow-haskell-bugs@haskell.org, or http://sourceforge.net/projects/ghc/. Prelude -W-M- @ @ | \_/ ___ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

### [Haskell] build an interpreter on top of GHCi?

Hi All, Does anybody has the experience to built an interpreter on top of GHCi? What I want is to defined a my own interpreter as a Haskell module and load it into GHCi. So this new interpreter will be running on top of GHCi which accepts syntax extension of Haskell. For example: Prelude :l myInter Prelude myInter new language source Prelude myInter ... Prelude myInter exit Prelude In another word, I want to have a read-eval-print-loop running on GHCi. Does anybody know how to do that? -W-M- @ @ | \_/ ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell

### [Haskell] parser for Typing Haskell in Haskell

Hi All, Does anybody know what parser Typing Haskell in Haskell use? I am tring to use the code for some type checking. But I cannot find a parser in the distribution. -W-M- @ @ | \_/ ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

### constrained datatype

Hi All, Anybody knows why the following code does not work? class Foo n data Erk n = Foo n = Erk test.hs:53: All of the type variables in the constraint `Foo n' are already in scope (at least one must be universally quantified here) When checking the existential context of constructor `Erk' In the data type declaration for `Erk' Failed, modules loaded: none. Is there any reason for this error? -W-M- @ @ | \_/ ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

### Re: *safe* coerce, for regular and existential types

I admire the elegancy of your code which makes the changes to add new data types minimum. There is one question I want to ask: Does this technique extend to polymophic types? Let's say we have the following type: data D a = C | D a Is it possible to index the type D a? Or there is some fundmental limitations which make it not achievable by Haskell type classes? -W-M- @ @ | \_/ On Thu, 31 Jul 2003 [EMAIL PROTECTED] wrote: This message describes functions safeCast and sAFECoerce implemented in Haskell98 with common, pure extensions. The functions can be used to 'escape' from or to existential quantification and to make existentially-quantified datatypes far easier to deal with. Unlike Dynamic, the present approach is pure, avoids unsafeCoerce and unsafePerformIO, and permits arbitrary multiple user-defined typeheaps (finite maps from types to integers and values). An earlier message [1] introduced finite type maps for purely-functional conversion of monomorphic types to unique integers. The solution specifically did not rely on Dynamic and therefore is free from unsafePerformIO. This message shows that the type maps can be used for a safe cast, in particular, for laundering existential types. The code in this message does NOT use unsafePerformIO or unsafeCoerce. To implement safe casts, we define a function sAFECoerce -- which works just like its impure counterpart. However the former is pure and safe. sAFECoerce is a library function expressed in Haskell with common extension. The safety of sAFECoerce is guaranteed by the typechecker itself. This whole message is self-contained, and can be loaded as it is in GHCi, given the flags -fglasgow-exts -fallow-undecidable-instances -fallow-overlapping-instances This message was inspired by Amr Sabry's problem on existentials. In fact, it answers an unstated question in Amr Sabry's original message. It has been observed on this list that existentially-quantified datatypes are not easy to deal with [2]. For example, suppose we have a value of a type data EV = forall a. (TypeRep a TI)= EV a (please disregard the second argument of TypeRep for a moment). The constructor EV wraps a value. Suppose we can guess that the wrapped value is actually a boolean. Even if our guess is correct, we *cannot* pass that value to any function of booleans: * *Main case (EV False) of (EV x) - not x * * interactive:1: * Inferred type is less polymorphic than expected * Quantified type variable `a' is unified with `Bool' * When checking an existential match that binds * x :: a * and whose type is EV - Bool * In a case alternative: (EV x) - not x A quantified type variable cannot be unified with any regular type -- or with another quantified type variable. Values of existentially quantified types cannot be passed to monomorphic functions, or to constrained polymorphic functions (unless all their constrains have been mentioned in the declaration of the existential). That limitation guarantees safety -- on the other hand, it significantly limits the convenience of existential datatypes [2]. To overcome the limitation, it _seemed_ that we had to sacrifice purity. If we are positive that a particular existentially quantified value has a specific type (e.g., Bool), we can use unsafeCoerce to cast the value into the type Bool [3]. This approach is one of the foundations of the Dynamic library. The other foundation is an ability to represent a type as a unique run-time value, provided by the methods of the class like TypeRep. Given an existentially quantified value and a value of the desired type, Dynamic compares type representations of the two values. If they are the same, we can confidently use unsafeCoerce to cast the former into the type of the latter. This works, yet leaves the feeling of dissatisfaction. For one thing, we had to resort to an impure feature. More importantly, we placed our trust in something like TypeRep and its members, that they give an accurate and unique representation of types. But what if they lie to us, due to a subtle bug in their implementation? What if they give the same representation for two different types? unsafeCoerce will do its dirty work nevertheless. Using the result would lead to grave consequences, however. This message describes sAFECoerce and the corresponding safe cast. Both functions convert the values of one type into the target type. One or both of these types may be existentially quantified. When the source and the target types are the same, both functions act as the identity function. The safe cast checks that the type representations of the source and the target types are the same. If they are, it invokes sAFECoerce. Otherwise, we monadically fail. The function sAFECoerce does the conversion without any type checking. It always returns the value of the target type. If the source type was the same as the

### dynamics on polymorphic datatype

Hi All, I am trying to perform dynamic casting on polymorphic types. Let's say I have a data type like: data Foo a = Foo a Is there any way to use dynamics to convert a value of type Foo a to a type reprentation? I try to use the toDyn in the dynamic libray, it complains for ambigours a. Is there a solution to it? Thank you very much. -W-M- @ @ | \_/ ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

### polymorphic type in state of state monad

Hi All, Any one of your have the experience of defining a state of a state monad as a polymorphic type? I want to have: type State = Term a = [a] data M a = M (State - IO(State,a)) GHC yields a error message Illegal polymorphic type. How to resolve this? Thank you very much. -W-M- @ @ | \_/ ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

### escape from existential quantification

I understand that existentially bound types cannot escape. For example, say we have data Foo = forall a. Foo Int a Then we cannot define a function extract (Foo i a) = a However,this limitation makes it extremly difficult to program with local quantifications.Is there any way to by pass this? -W-M- @ @ | \_/ ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell