core comparison for fun.

John Meacham john at repetae.net
Thu Feb 2 21:31:46 EST 2006


Just for larks, here is a side by side of the various compilers core for
the example on that page:

Haskell:

> module FibMain where
>
> main xs = pam daeh xs
>
> daeh (x:xs) = x
>
> pam f [] = []
> pam f (x:xs) = f x : pam f xs

Yhc:

> FibMain.pam v220 v221 =
>     case v221 of
>         Prelude.[] -> (Prelude.[])
>         Prelude.: v222 v223 ->
>             (Prelude.: (YHC.Internal._apply1 v220 v222) (FibMain.pam v220 v223))
>
> FibMain.daeh v224 =
>     case v224 of
>          Prelude.: v225 v226 -> v225
>          _ -> (Prelude.error (LAMBDA228))
>
> LAMBDA228 =
>     (prim_STRING "FibMain: Pattern match failure in function at 7:1-7:15.")
>
> FibMain.main v227 = (FibMain.pam FibMain.daeh v227)


Jhc:  (unicodey!)

> FibMain.main = ΛFibMain.v22.λFibMain.1_xs∷[[FibMain.v22]].(let
>         x9282∷[FibMain.v22] → FibMain.v22 = λx9284∷[FibMain.v22].(case x9284 of
>                 (x9286∷FibMain.v22):(x9288∷[FibMain.v22]) → x9286;
>                 Prelude.[] →
>                     <⊥:test/fibmain.hs:5:13: Unmatched pattern∷FibMain.v22>;);
>         x9280∷⋆ = [FibMain.v22];
>         in FibMain.pam x9280 FibMain.v22 x9282 FibMain.1_xs)
> FibMain.pam = ΛFibMain.v5.ΛFibMain.v10.λx9296∷FibMain.v5 → FibMain.v10.λx9298∷[FibMain.v5].(case x9298 of
>         (x9300∷FibMain.v5):(x9302∷[FibMain.v5]) → let x9316∷[FibMain.v10] =
>                                                           FibMain.pam FibMain.v5 FibMain.v10 x9296 x9302;
>                                                       x9314∷FibMain.v10 =
>                                                           x9296 x9300;
>                 in x9314:x9316;
>         Prelude.[] → "";)
> FibMain.daeh = ΛFibMain.v15.λx9284∷[FibMain.v15].(case x9284 of
>         (x9286∷FibMain.v15):(x9288∷[FibMain.v15]) → x9286;
>         Prelude.[] →
>             <⊥:test/fibmain.hs:5:13: Unmatched pattern∷FibMain.v15>;)

ghc:

>   daeh :: %forall a . [] a -> a =
>     \ @ a (ds::[] a) ->
> 	%case (a) ds %of (wild::[] a)
> 	  {[] ->
> 	     GHC.Err.patError @ a
> 	     ("test/fibmain.hs:5:0-14|function daeh"::Addr#);
> 	   : (x::a) (xs::[] a) ->
> 	     x};
>   pam :: %forall a a1 . (a -> a1) ->
> 			[] a -> [] a1 =
>     \ @ a @ a1 ->
> 	%let %rec
> 	     {pam1 :: (a -> a1) -> [] a -> [] a1 =
> 		\ (f::a -> a1) (ds::[] a) ->
> 		    %case (([] a1)) ds %of (wild::[] a)
> 		      {[] ->
> 			 [] @ a1;
> 		       : (x::a) (xs::[] a) ->
> 			 : @ a1 (f x) (pam1 f xs)}}
> 	%in pam1;
>   main :: %forall a . [] ([] a) ->
> 		      [] a =
>     \ @ a (xs::[] ([] a)) ->
> 	FibMain.pam @ ([] a) @ a (FibMain.daeh @ a) xs;



I don't think a common compiler level core is forthcoming :)


        John


--
John Meacham - ⑆repetae.net⑆john⑈


More information about the Haskell-prime mailing list