hpaste

recent | annotate | new

module Test where

import Prelude ((.), fst, snd, compare)
import Data.List.Stream

longest_word =
  fst .
  maximumBy (\x y -> compare (snd x) (snd y)) .
  map (\w -> (w, length w)) .
  words

==================== Tidy Core ====================
Rec {
Test.$s$wloop_maximumBy :: GHC.Prim.Int#
			   -> [[GHC.Base.Char]]
			   -> [GHC.Base.Char]
			   -> (# [GHC.Base.Char], GHC.Base.Int #)
[GlobalId]
[Arity 3
 NoCafRefs]
Test.$s$wloop_maximumBy =
  \ (x#_afP :: GHC.Prim.Int#)
    (xs_aof :: [[GHC.Base.Char]])
    (ww_srz :: [GHC.Base.Char]) ->
    case xs_aof of wild1_aob {
      [] -> (# ww_srz, GHC.Base.I# x#_afP #);
      : x_aoe xs1_Xom ->
	case Data.List.Stream.$wlen @ GHC.Base.Char x_aoe 0 of ww1_afr { __DEFAULT ->
	case GHC.Prim.<# x#_afP ww1_afr of wild_afX {
	  GHC.Base.False ->
	    case GHC.Prim.==# x#_afP ww1_afr of wild11_ag0 {
	      GHC.Base.False -> Test.$wloop_maximumBy ww_srz (GHC.Base.I# x#_afP) xs1_Xom;
	      GHC.Base.True -> Test.$wloop_maximumBy x_aoe (GHC.Base.I# ww1_afr) xs1_Xom
	    };
	  GHC.Base.True -> Test.$wloop_maximumBy x_aoe (GHC.Base.I# ww1_afr) xs1_Xom
	}
	}
    }
Test.$wloop_maximumBy :: [GHC.Base.Char]
			 -> GHC.Base.Int
			 -> [[GHC.Base.Char]]
			 -> (# [GHC.Base.Char], GHC.Base.Int #)
[GlobalId]
[Arity 3
 NoCafRefs
 Str: DmdType LLS]
Test.$wloop_maximumBy =
  \ (ww_srz :: [GHC.Base.Char])
    (ww1_srA :: GHC.Base.Int)
    (ww2_srE :: [[GHC.Base.Char]]) ->
    case ww2_srE of wild1_aob {
      [] -> (# ww_srz, ww1_srA #);
      : x_aoe xs_aof ->
	case ww1_srA of wild_afN { GHC.Base.I# x#_afP ->
	case Data.List.Stream.$wlen @ GHC.Base.Char x_aoe 0 of ww3_afr { __DEFAULT ->
	case GHC.Prim.<# x#_afP ww3_afr of wild11_afX {
	  GHC.Base.False ->
	    case GHC.Prim.==# x#_afP ww3_afr of wild12_ag0 {
	      GHC.Base.False -> Test.$wloop_maximumBy ww_srz wild_afN xs_aof;
	      GHC.Base.True -> Test.$wloop_maximumBy x_aoe (GHC.Base.I# ww3_afr) xs_aof
	    };
	  GHC.Base.True -> Test.$wloop_maximumBy x_aoe (GHC.Base.I# ww3_afr) xs_aof
	}
	}
	}
    }
end Rec }

Test.lvl :: [GHC.Base.Char]
[GlobalId]
[]
Test.lvl = GHC.Base.unpackCString# "maximumBy"

Test.a :: ([GHC.Base.Char], GHC.Base.Int)
[GlobalId]
[]
Test.a = Data.Stream.errorEmptyStream @ ([GHC.Base.Char], GHC.Base.Int) Test.lvl

Test.longest_word :: GHC.Base.String -> [GHC.Base.Char]
[GlobalId]
[Arity 1
 Str: DmdType L]
Test.longest_word =
  \ (x_aeG :: GHC.Base.String) ->
    case Data.List.Stream.words x_aeG of wild1_aob {
      [] ->
	Test.a
	`cast` (CoUnsafe ([GHC.Base.Char], GHC.Base.Int) [GHC.Base.Char]
		:: ([GHC.Base.Char], GHC.Base.Int) ~ [GHC.Base.Char]);
      : x1_aoe xs_aof ->
	case Test.$wloop_maximumBy
	       x1_aoe
	       (case Data.List.Stream.$wlen @ GHC.Base.Char x1_aoe 0 of ww_afr { __DEFAULT ->
		GHC.Base.I# ww_afr
		})
	       xs_aof
	of ww_srK { (# ww1_srM, ww2_srN #) ->
	ww1_srM
	}
    }




==================== Tidy Core Rules ====================
"SC:$wloop_maximumBy0" [0]
    forall {x#_afP :: GHC.Prim.Int#
	    xs_aof :: [[GHC.Base.Char]]
	    ww_srz :: [GHC.Base.Char]}
      Test.$wloop_maximumBy ww_srz (GHC.Base.I# x#_afP) xs_aof
      = Test.$s$wloop_maximumBy x#_afP xs_aof ww_srz



-- Int# to (# String, Int# #) !!

M.$s$wloop_maximumBy :: GHC.Prim.Int#
                        -> [[GHC.Base.Char]]
                        -> [GHC.Base.Char]
                        -> (# [GHC.Base.Char], GHC.Base.Int #)
[GlobalId]
[Arity 3
 NoCafRefs]
M.$s$wloop_maximumBy =
  \ (x#_ac2 :: GHC.Prim.Int#)
    (xs_akK :: [[GHC.Base.Char]])
    (ww_so4 :: [GHC.Base.Char]) ->
    case xs_akK of wild1_akG {
      [] -> (# ww_so4, GHC.Base.I# x#_ac2 #);
      : x_akJ xs1_XkR ->
        case Data.List.Stream.$wlen @ GHC.Base.Char x_akJ 0 of ww1_abD { __DEFAULT ->
        case GHC.Prim.<# x#_ac2 ww1_abD of wild_aca {
          GHC.Base.False ->
            case GHC.Prim.==# x#_ac2 ww1_abD of wild11_acd {
              GHC.Base.False -> M.$s$wloop_maximumBy x#_ac2 xs1_XkR ww_so4;
              GHC.Base.True -> M.$s$wloop_maximumBy ww1_abD xs1_XkR x_akJ
            };
          GHC.Base.True -> M.$s$wloop_maximumBy ww1_abD xs1_XkR x_akJ
        }
        }
    }




import Data.Ord
import Prelude hiding (map , length, words)
import Data.List.Stream
import qualified Data.ByteString.Char8 as S

longest_word = fst
             . maximumBy (comparing snd)
             . map (\w -> (w, S.length w))
             . S.words

main = print . longest_word =<< S.readFile "/usr/share/dict/words"

import Data.Ord
import Prelude hiding (length, words)
import Data.List.Stream
import qualified Data.ByteString.Char8 as S

longest_word = maximumBy (comparing S.length) . S.words

main = print . longest_word =<< S.readFile "/usr/share/dict/words"