POV-Ray : Newsgroups : povray.off-topic : Enter the compiler : Re: Enter the compiler Server Time
6 Oct 2024 07:04:49 EDT (-0400)
  Re: Enter the compiler  
From: Orchid Win7 v1
Date: 5 Mar 2015 13:37:20
Message: <54f8a260$1@news.povray.org>
On 03/03/2015 10:45 PM, Orchid Win7 v1 wrote:
> It's a tad verbose (!!), but it works. The protocol is that every
> top-level Haskell constant becomes a
>
> public static Thunk<...> OB_XXX = ...
>
> Any top-level constant that's a *function* also gets a
>
> public static T0 FN_XXX(Thunk<T1> arg1, Thunk<T2> arg2, Thunk<T3> args)
> {
> ...compiled code...
> }

...yeah, that doesn't actually work.

Haskell allows you to declare a "constant" who's type is polymorphic. C# 
does not.

For example:

   data MinHeap x = Empty | Node x (MinHeap x) (MinHeap x)

   empty :: MinHeap x
   empty = Empty

You *think* you can do this:

   public abstract class TC_MinHeap<Tx> {...}

   public sealed class VC_Empty<Tx> : TC_MinHeap<Tx> {...}

   public sealed class VC_Node<Tx> : TC_MinHeap<Tx> {...}

   public static readonly TC_MinHeap<Tx> OB_empty = new VC_Empty<Tx>();

Alas, that won't work. Outside of VC_Empty, the Tx variable is 
out-of-scope. The only way is to create a generic *method*:

   public static TC_MinHeap<Tx> OB_empty<Tx>()
   {
     return new VC_Empty<Tx>();
   }

Annoyingly, that means creating a brand-new VC_Empty<Tx> object for 
every possible type Tx. [And possibly several identical ones for a given 
type, if OB_empty gets accessed more than once.] Damned phantom types! :-P

The native C version, of course, can just tell the type system to go 
take a walk. I don't think you can do that in C#. (Well, short of 
casting everything to Object, and that's just not funny...)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.