Here is some strange question:
  how to force the compiler to evaluate some things more statically
  and to convert some run-time errors into the compile-time ones?
Example.
  f :: [Int] -> Int 
  f    xs    = if  any (> 4) xs  then  error "f xs:  x > 4 among xs"
               else                    sum xs
  (a,b) = (2,6)
  g,h,h' :: [Int] -> [Int]
  g     = f <some complex expression to produce a list>
  h  ys = f (a:b:ys)
  h' ys = f ([0..10]++ys)

The "human" compilation detects that  h  and  h'  yield  (error..)  
for each argument  ys.
In many cases, the programmer would like the compiler to stop 
compiling N and report something like 
                                Error:  h  always yields (error...).

How it occurs that the programmer sets the expressions like 
                   f (a:b:...),  with (a,b) = (2,6) 
if one knows that  f  does with these  a,b ?

This occurs by mistake, similarly as, for example, applying  x+y ::T
with T not of Num instance.

This feature can be considered as the correctness check via a bit of
partial evaluation.

Imagine the programmer writes in above situation

  f xs = {-# static <n> 
           if  any (> 4) xs  then  error "f xs:  x > 4 among xs"
           else                    sum xs
         #-}
This should mean that everywhere, seeing  f  applied, the compiler
tries to find statically the value under {-# static ..#-}
and computes ("unfolds" ?) expressions to the depth  <n>.
<n> is the bound for the static analysis expansion.
(I doubt on modularity, though. Let us assume so far, there is only 
one module).
If it succeeds in computing this value  v,  it inserts  v  into the
compiled code. 
And if this  v  occurs  (error...),  then it reports this at the 
compile-time.
If the result  v  is not visible, compile as usual.

The reason for this is that some programs have many correctness
conditions that are similar to the condition of some class instance 
existence, but *should not* (or cannot) be expressed via the classes
and instances. They should be expressed in terms of the ordinary 
parameter values.

For example, let for the data  D xs :: D [a]  there are declared 
the class instances  CC = C1, C2 .. C9.
But different instances from  CC  are really correct or not, 
depending on the four conditions
                      length xs = 0, 1, 2,  or > 2.

And in various places in the program there are set things like 
               D [x],  D [x,1,x],  D (1:2:ys) where ys = ...

The first two are desired to be checked statically, the third may 
delay to the run-time.
I recall also someone in this list asked about more possibility to 
compute statically the constants. 

------------------
Sergey Mechveliani
[EMAIL PROTECTED]






Reply via email to