Hello,
The type of the monadic bind function in the Monad class is
Monad m = m a - (a - m b) - m b
Now, would it be possible to create a monad with a slightly stricter
type, like
StrictMonat m = m a - (a - m a) - m a
and, accepting that all steps of the computation would be bound to
Hello,
after succeeding in implementing my first monad (Counter, it increments
a counter every time a computation is performed) I though I'd try
another one and went on to implement Tracker.
Tracker is a monad where a list consisting of the result of every
computation is kept alongside the final
Dan Doel wrote:
Thus, unfortunately, you won't be able to implement the general bind
operator. To do so, you'd need to have Tracker use a list that can
store values of heterogeneous types, which is an entire library unto
itself (HList).
Telling me that it just won't work was one of the best
Benjamin Franksen wrote:
Partially applying Tracker to one argument ('T a') gives you a type
constructor that has only one remaining 'open' argument and thus can be
made an instance of class Monad.
Totally clear, thanks a lot (also to Keegan).
Julien
Hello,
I was just doing Exercise 7.1 of Hal Daumé's very good Yet Another
Haskell Tutorial. It consists of 5 short functions which are to be
converted into point-free style (if possible).
It's insightful and after some thinking I've been able to come up with
solutions that make me
Julien Oster wrote:
But I'm having problems with one of the functions:
func3 f l = l ++ map f l
While we're at it: The best thing I could come up for
func2 f g l = filter f (map g l)
is
func2p f g = (filter f) . (map g)
Which isn't exactly point-_free_. Is it possible to reduce
Duncan Coutts wrote:
Hi,
In practise I expect that most programs that deal with file IO strictly
do not handle the file disappearing under them very well either. At best
the probably throw an exception and let something else clean up.
And at least in Unix world, they just don't disappear.
Udo Stenzel wrote:
Thank you all a lot for helping me, it's amazing how quickly I received
these detailed answers!
func2 f g l = filter f (map g l)
func2 f g = (filter f) . (map g) -- definition of (.)
func2 f g = ((.) (filter f)) (map g) -- desugaring
func2 f = ((.) (filter f)) . map
Julien Oster wrote:
= ((.) (filter f)) . map g l
= (.)((.) . filter f)(map) g l -- desugaring
= (.map)((.) . filter f) g l -- sweeten up
= (.map) . (.) . filter g l-- definition of (.)
By the way, I think from now on, when doing point-free-ifying