Building snapshot ghc-5.05.20030123 on macOSX

2003-02-12 Thread Arthur Baars
I want to play a bit with Template Haskell, so I downloaded a cvs 
snapshot (ghc-5.05.20030123.tar.gz) and tried to compile
it on my mac (OSX 10.2).  I figured out that I needed a stage2 or 
stage3 compiler to get TH working, so I tried 'make stage3' .
GHC started to compile itself three times. At lot of hours later it 
finished.

Unfortunately, when I tried run the thing on a Prinf example, I got the 
following message.
compiler/stage3- ./ghc-inplace -c Printf.hs -fglasgow-exts -package 
haskell-src
Template Haskell  bracket illegal in a stage-1 compiler
  [| \s - s |]

The thing incompiler/stage3  was just a stage-1 compiler, so ghc had 
achieved nothing useful after re-compiling three times :-(
The problem is that GHCi support is not turned on for MacOSX. I guess 
GHCi is used to do compile-time evaluation of code for TH.

In file mk/config.mk.in it says:

# Include GHCi in the compiler.  Default to NO for the time being.

ifneq $(findstring $(HostOS_CPP), mingw32 cygwin32 linux solaris2 
freebsd netbsd openbsd) 
GhcWithInterpreter=YES
else
GhcWithInterpreter=NO
endif

In the list of supported systems MacOSX is missing. After adding 
darwin to this list, and waiting for hours, I got a working 
TH-compiler.

Can someone add OSX(darwin) to the mk/config.mk.in file? It would 
also be nice to get a warning
if one tries to compile a stage-(N1) compiler without GHCi support.

Cheers,

Arthur

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Existentials and newtype

2001-11-22 Thread Arthur Baars

At [EMAIL PROTECTED] I asked the following:

 this works

data Exists f = forall x . E ( f  x)

 this doesn't work

 newtype Exists f = forall x . E ( f  x)

 Hugs accepts both.

 It there a reason why existential quantification does not work with a
 newtype, or is it just
 a parser problem?

This problem is clearly not a bug but a restriction imposed by the designers
of GHC,
as Keith Wansbrough pointed out to me:

 From the manual, section 7.12.3 Restrictions:

 --8--
 You can't use existential quantification for newtype declarations. So this
is illegal:
   newtype T = forall a. Ord a = MkT a

 Reason: a value of type T must be represented as a pair of a
 dictionary for Ord t and a value of type t. That contradicts the idea
 that newtype should have no concrete representation. You can get just
 the same efficiency and effect by using data instead of newtype. If
 there is no overloading involved, then there is more of a case for
 allowing an existentially-quantified newtype, because the data because
 the data version does carry an implementation cost, but single-field
 existentially quantified constructors aren't much use. So the simple
 restriction (no existential stuff on newtype) stands, unless there are
 convincing reasons to change it.
 --8--

I perfectly understand why the use of class constraints in combination with
newtype and existential quantification is
illegal. In my opinion the restriction should only forbit this particular
combination, instead of all uses of newtype with existentials.

For me single-field existentially quantified constructors are quite useful:

For example

newtype Exists f = forall x . E (f x)

data Object a = Object {value :: a , toString:: a - String }

data Thing a = Thing {val :: a , next :: a - a,  run :: a - IO ()}

-- Here I hide the type variables of Object and Thing using the type Exists:

type EObject  = Exists Object
type EThing= Exists Thing

without single-field existentially quantified constructors I would have to
write:

data EObject =  forall  a . EObject a (a - String)
data EThing   =  forall a . EThing  a  (a - a)  (a- IO ())

or write the Exists type using data

When using data I have to pay a (however small) run-time cost, that I would
not have to pay
when using a newtype.

The other solution does not have this run-time cost, but it makes my code
less readable:
I have to invent new types and constructor names.
I cannot use named fields.
I cannot reuse polymorphic functions that work on Object on EObjects.

Summarizing: without single-field existentially quantified constructors in
newtypes
either my code gets less readable or I have to pay a run-time price.
 Is it possible to relax the restriction on newtypes in combination with
existentials?

Cheers, Arthur











___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users