here is a reduced program that still segfaults:<div><br></div><div><div>{-# LANGUAGE Arrows #-}</div><div><br></div><div>import Control.Arrow</div><div><br></div><div>main :: IO ()</div><div>main = print segfault</div><div>
<br></div><div>segfault :: [()]</div><div>segfault = anythingYouWant ()</div><div><br></div><div>anythingYouWant :: a</div><div>anythingYouWant = testB False (const ()) ()</div><div><br></div><div>testB :: ArrowChoice arrow </div>
<div> => bool -> arrow () () -> arrow () anything</div><div>testB bool arrow =</div><div> proc () -></div><div> do if bool then arrow -< ()</div><div> else arrow -< ()</div><div><br>
</div><div>Sebastian</div><div><br></div><div class="gmail_quote">On Fri, Aug 5, 2011 at 6:20 AM, Brent Yorgey <span dir="ltr"><<a href="mailto:byorgey@seas.upenn.edu">byorgey@seas.upenn.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Tue, Aug 02, 2011 at 05:08:33PM -0400, bob zhang wrote:<br>
> hi, all<br>
> testB :: (ArrowChoice t1, Num a1, Num a) => (a -> a1 -> t2) -> t1 a t3<br>
> -> t1 a1 t3 -> t1 (a, a1) t<br>
> testB f g h = proc (x,y) -> do<br>
> if (f x y)then g -< x + 1 else h -< y + 2<br>
><br>
> it's very strange that the type of _f_ is (a->a1->t2) which I thought<br>
> should be a -> a1 -> Bool,<br>
><br>
> btw, is there any way to get the output of preprocessing using -XArrow<br>
> extensions,<br>
><br>
> Thanks a lot<br>
> best, bob<br>
<br>
</div>Congratulations, you have definitely found a GHC bug! Note there are<br>
actually two things wrong with testB's type signature: first, t2 ought<br>
to be Bool, as you note. But even worse, notice that the return type<br>
of the result arrow, t, has nothing to do with any of the other types!<br>
This means that we can use testB along with the (->) instance for<br>
Arrow to construct elements of arbitrary types:<br>
<br>
ghci> let anythingYouWant = testB (\x y -> False) (const 3) (const 2) (2,2)<br>
ghci> :t anythingYouWant<br>
anythingYouWant :: t<br>
ghci> anythingYouWant :: Integer<br>
2<br>
ghci> anythingYouWant :: Int<br>
2<br>
ghci> anythingYouWant :: Double<br>
1.0e-323<br>
ghci> anythingYouWant :: Char<br>
'\STX'<br>
ghci> (anythingYouWant :: (Double -> Double) -> [Double]) sqrt<br>
[<br>
[1] 17391 segmentation fault ghci<br>
<br>
whoops!<br>
<br>
I'm using GHC 7.0.3, but Daniel Wagner and I also tried it (with the<br>
same results) on GHC 7.2.0rc1 and GHC HEAD.<br>
<br>
I wasn't able to find a ticket for this on the GHC bug tracker, I<br>
guess we should file one!<br>
<br>
I tried to find a way to get the output of preprocessing using -XArrow<br>
but wasn't able to find one (other than -ddump-ds which gives you the<br>
unoptimized *GHC core* output, which is quite hard to read).<br>
<font color="#888888"><br>
-Brent<br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>