@ has joined the channel
MonomorphismRestriction
が働いて、 Int
か何かに特殊化された quickSortVec
が作られたのではないかと。quickSortVec :: _
_
を書くと推論した結果を表示してくれるのですがInt -> Int -> VM.MVector (PrimState m0) a0 -> m0 ()
quickSortVec :: (PrimMonad m, VM.Unbox a, Ord a) => Int -> Int -> VM.MVector (PrimState m) a -> m ()
quickSortList :: [(Int, (Int, Int))] -> [(Int, (Int, Int))] quickSortList :: (Ord a, VM.Unbox a) => [a] -> [a]
:t
がその結果を出したのは、`quickSortList` も多相化されているからではないかと思います。quickSortList
の型を書いていても quickSortVec
に型を書かなければ Int
に特殊化できていたのは、おそらく quickSortList
がインライン化されたからではないかと思います。(GHCが最適化注に気づいて)インライン化した時点で quickSortList
は Int
に特殊化された、と。quickSortList
に対する型注釈を消した上で :t
してみると、kakkun61が今上げたような結果になり、無事最適化がかかると思います。PrimMonad m =>
が付く関数定義は全てインライン化するのが定石です。これを忘れると、その中のすべての(>>=)が辞書渡しになるので、非常に遅くなるのは必至です(会社のコードにもそのような部分を見つけたばかりです…)default (Int, Double)
stack install gtk
extra-deps: - gi-pangocairo-1.0.23@sha256:04dacf055fef4e19dd0276a8c2b5df08332877600b0014beecd2eaa764495ec6,3158 - cairo-0.13.8.0@sha256:9b64a376ebaa4f153bba5866a32291fd4bed48147009cce9158ce6533928eba8,4075 - gtk2hs-buildtools-0.13.8.0@sha256:132f38155fc677430a47ea750918973161c876fb6f281d342ac2f07eb99229ce,5238 - gio-0.13.8.0@sha256:5691212b07dc4193ea6f8202a625c9515d750b249aeafc659139e29a5ec61436,3116 - glib-0.13.8.0@sha256:97698bd054bad38756f3ef0220d7684f72e42660d261e9b118aa73419ce9207d,3136 - pango-0.13.8.0@sha256:690149ea2efb03c783937b69a5ec6ac854806146fd760e28e800634a6c2243c1,3897
09/glib-0.13.8.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup/setup ... glib > Configuring glib-0.13.8.0... glib > build glib > Preprocessing library for glib-0.13.8.0.. glib > setup: Error in C header file. glib > glib > /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/time.h:153: (column 17) [FATAL] glib > >>> Syntax error! glib > The symbol `__attribute__' does not fit here.
cabal: Encountered missing dependencies: gi-cairo -any, gi-gdk -any, gi-glib -any, gi-gtk -any, gi-gtk-hs -any, gi-pango -any, gi-pangocairo -any, haskell-gi-base -any
cabal install gtk --with-gcc=gcc-9
Graphics/UI/Gtk/Embedding/Socket.chs:175:6: error: • Couldn't match expected type 'Ptr ()' with actual type 'Maybe DrawWindow' • In the second argument of '\ (Socket arg1) arg2 -> withForeignPtr arg1 $ \ argPtr1 -> gtk_socket_add_id argPtr1 arg2', namely '(fromNativeWindowId windowId)' In the expression: (\ (Socket arg1) arg2 -> withForeignPtr arg1 $ \ argPtr1 -> gtk_socket_add_id argPtr1 arg2) (toSocket self) (fromNativeWindowId windowId) In an equation for 'socketAddId': socketAddId self windowId = (\ (Socket arg1) arg2 -> withForeignPtr arg1 $ \ argPtr1 -> gtk_socket_add_id argPtr1 arg2) (toSocket self) (fromNativeWindowId windowId) | 175 | (fromNativeWindowId windowId) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Graphics/UI/Gtk/Embedding/Socket.chs:187:3: error: • Couldn't match type 'Ptr ()' with 'Maybe DrawWindow' Expected type: IO (Maybe DrawWindow) Actual type: IO (Ptr ()) • In the second argument of '($)', namely '(\ (Socket arg1) -> withForeignPtr arg1 $ \ argPtr1 -> gtk_socket_get_id argPtr1) (toSocket self)' In the expression: liftM toNativeWindowId $ (\ (Socket arg1) -> withForeignPtr arg1 $ \ argPtr1 -> gtk_socket_get_id argPtr1) (toSocket self) In an equation for 'socketGetId': socketGetId self = liftM toNativeWindowId $ (\ (Socket arg1) -> withForeignPtr arg1 $ \ argPtr1 -> gtk_socket_get_id argPtr1) (toSocket self) | 187 | {# call unsafe socket_get_id #} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... cabal: Leaving directory '/var/folders/hd/fpfqf1rs28g30x7rcffkyrnh0000gp/T/cabal-tmp-79499/gtk-0.15.4' cabal: Error: some packages failed to install: gtk-0.15.4-8aDu81HrSCJZyllLlxBkN failed during the building phase. The exception was: ExitFailure 1
$ brew install gcc $ cabal build --with-gcc=gcc-9
$ stack install gtk
{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} module Data.Extensible.Envy ( recordFromEnv ) where import Data.Extensible ((:&), Forall, Instance1) import qualified Data.Extensible as Ex import Data.Kind (Type) import Data.Proxy (Proxy (Proxy)) import GHC.TypeLits (KnownSymbol, Symbol) import qualified System.Envy as Env recordFromEnv :: forall (xs :: [Ex.Assoc Symbol Type]) h . Forall (Ex.KeyTargetAre KnownSymbol (Instance1 Env.Var h)) xs => Env.Parser (Ex.RecordOf h xs) recordFromEnv = Ex.hgenerateFor (Proxy :: Proxy (Ex.KeyTargetAre KnownSymbol (Instance1 Env.Var h))) f where f membership = Ex.Field <$> Env.env (Ex.stringKeyOf membership)
src\Data\Extensible\Envy.hs:25:88: error: • Couldn't match kind 'Symbol' with '*' When matching types kv1 :: Ex.Assoc * * x :: Ex.Assoc Symbol * Expected type: Ex.Membership xs x -> Env.Parser (Ex.Field h x) Actual type: Ex.Membership xs x -> Env.Parser (Ex.Field h kv1) • In the second argument of 'Ex.hgenerateFor', namely 'f' In the expression: Ex.hgenerateFor (Proxy :: Proxy (Ex.KeyTargetAre KnownSymbol (Instance1 Env.Var h))) f In an equation for 'recordFromEnv': recordFromEnv = Ex.hgenerateFor (Proxy :: Proxy (Ex.KeyTargetAre KnownSymbol (Instance1 Env.Var h))) f where f membership = Ex.Field <$> Env.env (Ex.stringKeyOf membership) | 25 | Ex.hgenerateFor (Proxy :: Proxy (Ex.KeyTargetAre KnownSymbol (Instance1 Env.Var h))) f | ^
PolyKinds
か...!site: PolyKinds
って検索したらこんなの出てきた笑カインドでエラーが出るときは、だいたい `PolyKinds` 拡張が足りない
*
と Symbol
が合わないっていってるわけだし...