In message <[EMAIL PROTECTED] >, Patrick M
aier writes:
> I have encountered a bug using the Hugs module STArray.
> When reading in the following lines
> 
> > import STArray
> 
> > test :: ST s Int
> > test = newArr (1,8) 0     >>= (\nums ->
> >        writeArr nums 5 42 >>= (\_ ->
> >        readArr nums 5     >>= (\v ->
> >        return v)))
> 
> and then calling
> 
> runST test
> 
> Hugs 1.4 responds with
> 
> ERROR: Type error in encapsulation
> *** expression     : runST test
> *** term           : test
> *** type           : ST a Int
> *** does not match : ST b Int
> 
> Using Hugs 1.3 to do the same I get the expected result
> 
> 42
> 
> I suspect there are bugs in type inference
> 
> Find them and kill them!
> 
>    Patrick Maier
>    [EMAIL PROTECTED]

The reported trouble was already found in 970203.  Included is a plausible
patch I've been using since then.  If you don't like the behaviour, you may
disable the effect of the patch by replace #if 0 with #if 1.

Note (1): Of course, this is _not_ an official patch.  This may help you
  only if you are so urge that you cannot wait for an official one. 
Note (2): Applying the diff. of type.c relaxes the encapsulation criterion.
  After that, you will have

     ST> :type runST (return 30)
     runST (return 30) :: Num a => a

  instead of a type error.   If you don't like this behaviour, disable
  the effect of this part as described above.

Hope this helps.

-----
Yoshihiko Ichikawa, Dept of Info Sci, Fac of Sci, Ochanomizu University
Phone:  +81-3-5978-5708 (Dial-in) / +81-3-5978-5704 (Library of Department)
Fax:    +81-3-5978-5898 (Faculty) / +81-3-5878-5705 (Library of Department)
E-mail: [EMAIL PROTECTED]


============%< ========================================================
*** preds.c.orig        Wed May 28 10:35:40 1997
--- preds.c     Wed May 28 10:35:25 1997
***************
*** 271,279 ****
--- 271,294 ----
  
        numFixedVars = 0;
        if (anyGenerics(t,o)) {                         /* contains generic*/
+ #if 0
            tl(preds) = qs;
            qs        = preds;
            evids     = cons(haskSimp(c,t,o),evids);
+ #else
+           Cell saveHpreds = hpreds;
+           Cell ev = haskSimp(c,t,o);
+           if (saveHpreds == hpreds) {
+               /* constant */
+               Cell d        = makeDictFor(ev,NIL);
+               fst(thd3(pi)) = mkSelect(0);
+               snd(thd3(pi)) = d;
+           } else {
+               tl(preds) = qs;
+               qs        = preds;
+               evids     = cons(haskSimp(c,t,o),evids);
+           }
+ #endif
        }
        else if (numFixedVars>0) {                      /* only fixed vars */
            tl(preds) = ps;
*** subst.c.orig        Tue Mar 11 03:46:02 1997
--- subst.c     Wed May 28 10:37:35 1997
***************
*** 273,281 ****
--- 273,295 ----
        case TYCON   :
        case TUPLE   : return;
  
+ #if 0
        case AP      : markType(fst(t),o);
                       markType(snd(t),o);
                       return;
+ #else
+ #  if LAZY_ST
+       case AP      : if (fst(t) != typeST) {
+                          markType(fst(t),o);
+                          markType(snd(t),o);
+                      }
+                      return;
+ #  else
+       case AP      : markType(fst(t),o);
+                      markType(snd(t),o);
+                      return;
+ #  endif
+ #endif
  
        case OFFSET  : markTyvar(o+offsetOf(t));
                       return;
*** type.c.orig Wed Apr  9 08:26:54 1997
--- type.c      Wed May 28 10:48:07 1997
***************
*** 828,833 ****
--- 828,834 ----
        savePreds = elimConstPreds(line,savePreds);
      markTyvar(beta+1);
      tyvarType(beta);
+ #if 0
      if (nonNull(preds) || typeIs!=var || tyvar(typeOff)->offs==FIXED_TYVAR) {
        Int  alpha  = newTyvars(2);
        Type actual = copyType(typeSTab,beta);
***************
*** 837,842 ****
--- 838,854 ----
        reportTypeError(line,snd(e),e,enc,actual,copyType(typeSTab,alpha));
      }
      preds = savePreds;
+ #else
+     if (typeIs!=var || tyvar(typeOff)->offs==FIXED_TYVAR) {
+       Int  alpha  = newTyvars(2);
+       Type actual = copyType(typeSTab,beta);
+       bindTv(alpha+1,var,beta+1);
+       if (nonNull(hpreds))
+           actual = ap(QUAL,pair(copyPreds(hpreds),actual));
+       reportTypeError(line,snd(e),e,enc,actual,copyType(typeSTab,alpha));
+     }
+     preds = revOnto(preds, savePreds);
+ #endif
      tyvarType(beta+1);
  }
  #endif
  • runST Patrick Maier
    • Yoshihiko ICHIKAWA

Reply via email to