@Sakae has joined the channel
callCCの型はなぜ`forall r m a. ((forall b. a -> ContT r m b) -> ContT r m a) -> ContT r m a`ではなく`forall r m a b. ((a -> ContT r m b) -> ContT r m a) -> ContT r m a`なのでしょうかvector-13.0.0 における newtype に対する Unbox 実装の質問です。U.Vector を使うだけなら、大きな差は無いと思って良いでしょうか。RecordWildCards 有効にすると、RecordWildCards を有効にすると暗黙に有効にされるDisambiguateRecordFields の効果なのかと思ったけどそういうわけでもないみたいです.module M where
data R = R { x :: String }{-# LANGUAGE RecordWildCards #-}
import M
inc :: Int -> Int
inc x = x + 1
getX :: R -> String
getX m = x mdata FunDecl = FunDecl String [([Pattern], Expr)]
Haskell
timeout :: Int -> IO a -> IO (Maybe a)
timeout n f
| n < 0 = fmap Just f
| n == 0 = return Nothing
| otherwise = do
-- In the threaded RTS, we use the Timer Manager to delay the
-- (fairly expensive) 'forkIO' call until the timeout has expired.
--
-- An additional thread is required for the actual delivery of
-- the Timeout exception because killThread (or another throwTo)
-- is the only way to reliably interrupt a throwTo in flight.
pid <- myThreadId
ex <- fmap Timeout newUnique
tm <- getSystemTimerManager
-- 'lock' synchronizes the timeout handler and the main thread:
-- * the main thread can disable the handler by writing to 'lock';
-- * the handler communicates the spawned thread's id through 'lock'.
-- These two cases are mutually exclusive.
lock <- newEmptyMVar
let handleTimeout = do
v <- isEmptyMVar lock
when v $ void $ forkIOWithUnmask $ \unmask -> unmask $ do
v2 <- tryPutMVar lock =<< myThreadId
when v2 $ throwTo pid ex
cleanupTimeout key = uninterruptibleMask_ $ do
v <- tryPutMVar lock undefined
if v then unregisterTimeout tm key
else takeMVar lock >>= killThread
handleJust (\e -> if e == ex then Just () else Nothing)
(\_ -> return Nothing)
(bracket (registerTimeout tm n handleTimeout)
cleanupTimeout
(\_ -> fmap Just f))forallを用いたデータ型について質問です.{-# LANGUAGE ExistentialQuantification #-}
module Bar where
data AnyBar b = forall a. AnyBar a (a -> b)
argBar :: AnyBar b -> b
argBar (AnyBar x f) = f x
letBar :: AnyBar b -> b
letBar ab = let AnyBar x f = ab in f xsrc/Bar.hs:11:26: error:
• Couldn't match expected type 'p1' with actual type 'a -> b'
'p1' is a rigid type variable bound by
the inferred types of
x :: p
f :: p1
at src/Bar.hs:11:17-31
• In the pattern: AnyBar x f
In a pattern binding: AnyBar x f = ab
In the expression: let AnyBar x f = ab in f x
• Relevant bindings include
ab :: AnyBar b (bound at src/Bar.hs:11:8)
letBar :: AnyBar b -> b (bound at src/Bar.hs:11:1)
|
11 | letBar ab = let AnyBar x f = ab in f x
| ^