To my 

| 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?

Simon Peyton-Jones <[EMAIL PROTECTED]>  writes

> Not strange at all.  It would be quite reasonable to have some way
> to tell the compiler 'evaluate this to a static value'.   I'd suggest
> doing it via a pseudo-function
>       static :: a -> a
>
> which behaved like the identity function, except that it evaluated
> its argument rather eagerly at compile time.  Implementing it would
> be a little delicate (because inlining is already a delicate part of
> GHC) but would not take much code.


Maybe, it requires some degree parameter d :: Int, how "far" to search. 
If the static computation of
                                               `static d f'
in this degree fails, it is replaced with `f'.
And probably, this should be a standard pragma  {-# static d ... #-} ? 

> About converting run-time to compile-time errors, as others have
> said, some functions are legitimately bottom. 

If I am not missing the subject, setting {-# static ..#-} or some 
special construct, the programmer re-defines deliberately what is 
legitimate.

> But think about assertions:
>
>       f x = assert (p x) (...x...)
>
> where assert :: Bool -> a -> a
>    

Why at all `assert' is needed when there exists `if':

        f x = if  p x  then  (...x...)  
              else           what-the-user-likes
- ?
In any case, `static' combined with  (if .. error)  or with 
`assert' may fit the aim.


Marc van Dongen <[EMAIL PROTECTED]>  writes
 
D> .. Also I would like a
D> assertAndBelieveMe which could be used to as in:
D> 
D> quot' a b | assertAndBelieveMe (b /= 0) = quot a b
D> 
D> So that a special version of quot could be used
D> which would not check for b == 0.

This looks like some different task for the compiler. 
Looks like a request for specializing any function  f x y ..  to the 
argument satisfying  (c' x y ..)

`quot' or any other function, may contain its "conditions" 
                                                      c1 x, c2 y ...
which it may find in the way of computation. 
Should we care only of the condition  x == a,  x /= a ?
The generic setting is 
                       "compute (f x y ..),  provided  (c' x y ..)"
That is specialize  f  to the argument satisfying the condition.
         
Now, the compiler has, for example, to guess, how  c' relates to  c1 
the function  f  contains. Looks difficult ...
The programmer could point explicitly: 
                 "... provided this precisely  c1 x  in  f  is  True". 

But for this, the programmer has to know the source of  f  and refer 
to its parts.

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


Reply via email to