Consider the following function: oddness :: Maybe Int oddness = do let a = Just 1 :: Maybe Int b >= \b -> return b And recall the definition of (>>=) for Maybe: instance Monad Maybe where (Just x) >>= k = k x Nothing >>= _ = Nothing So what’s happening here is that… Continue reading Do-notation can be misleading
Month: August 2014
C++ Guru Question – followup
(following on from C++ Guru Question) There are a few reasons why the code before didn’t work: mainly a) C++ template argument deduction works one-way with a list of candidates, it’s not H-M type inference. b) A C++ lambda is a thing with some internal type, not a std::function (although it can be assigned to… Continue reading C++ Guru Question – followup
C++ Guru Question
Wondering about this… template argument deduction succeeds for the explicitly-typed variable, fails in the auto case. (Also, it succeeds either way for an equivalently-typed unary operator template). template struct Foo { T m_t; }; template Foo operator/=(Foo foo, function fn) { return fn(foo.m_t); } void mystery() { auto foo = Foo{1}; // this works… function… Continue reading C++ Guru Question