On Thu, 16 Mar 2000, Chris Okasaki wrote:
>   newtype Foo = F Foo

Interesting loop hole you found there! Semantically it should be pretty
clear what this type means, just as the corresponding meaning on the
value level:

  bottom = bottom

Foo is simply Void! (formal def. later)
Void has been in Haskell, I can't really remember why it had to go - well
here it is again anyway!

> Admittedly, you could never construct a value of these
> types, but, even so, what do these types mean?

Sure you can - as all Haskell types it contains bottom (as defined
above) and for example

  void = Void void

which is just another way of defining bottom :: Void.

Semantically the meaning is the least fixed point of the identity functor,
that is the minimal CPO containing only _|_.

Hugs and hbc accept it without complaining. (I haven't got nhc installed.)

What is interesting is that ghc loops when trying to compile this
definition! (Ghc folks, consider this a bug report, details below!)

Patrik Jansson

====================
-- Some examples - all run in hugs and hbc
newtype Void = Void Void deriving Show
void :: Void
void = Void void

bottom :: a
bottom = bottom

newtype A = MkA B deriving Show
newtype B = MkB A deriving Show

a = MkA b
b = MkB a

bot_a = bot_b
bot_b = bot_a

newtype Stream a = C (a,Stream a) deriving Show
scons :: a -> Stream a -> Stream a
scons x xs = C (x,xs)
ones :: Stream Int
ones = scons 1 ones

newtype List a = L (Either () (a,List a)) deriving Show
nil :: List a
nil = L (Left ())
cons :: a -> List a -> List a
cons x xs = L (Right (x,xs))

toList :: [a] -> List a
toList = foldr cons nil

main = print void

=======================================================
minimal test case for ghc
cat >newtype.hs <<__END__
newtype Void = Void Void
main = print ()
__END__
And the output from ghc -v newtype.hs: [Unfortunate line breaks by my
mailer]

The Glorious Glasgow Haskell Compilation System, version 4.06

Effective command line: -v

Ineffective C pre-processor:
        echo '{-# LINE 1 "newtype.hs" -}' > /tmp/ghc779.cpp && cat
newtype.hs >> /tmp/ghc779.cpp
0.00user 0.00system 0:00.01elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (105major+14minor)pagefaults 0swaps
ghc:compile:Output file newtype.o doesn't exist
ghc:compile:Interface file newtype.hi doesn't exist
ghc:recompile:Input file newtype.hs newer than newtype.o

Haskell compiler:
        /usr/lib/ghc-4.06/ghc-4.06/hsc /tmp/ghc779.cpp
-fignore-interface-pragmas -fomit-interface-pragmas -fsimplify [
-fmax-simplifier-iterations4 ]   -fwarn-overlapping-patterns
-fwarn-missing-methods -fwarn-missing-fields -fwarn-duplicate-exports
-fhi-version=406 -static
"-himap=.%.hi:/usr/lib/ghc-4.06/ghc-4.06/imports/std%.hi" "-himap-sep=:"    -v
-hifile=/tmp/ghc779.hi -C=/tmp/ghc779.hc -F=/tmp/ghc779_stb.c
-FH=/tmp/ghc779_stb.h +RTS -H6000000 -K1000000
Glasgow Haskell Compiler, version 4.06, for Haskell 98, compiled by GHC
version 4.06

[ Time passes, eventually I press Ctrl-C ]

Command exited with non-zero status 252
89.31user 0.16system 1:30.49elapsed 98%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (1330major+1772minor)pagefaults 0swaps
deleting... /tmp/ghc779.cpp /tmp/ghc779.hi /tmp/ghc779.hc
/tmp/ghc779_stb.c /tmp/ghc779_stb.h

rm -f /tmp/ghc779*







Reply via email to