T. Morris

Greenhorn
+ Follow
since Sep 09, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by T. Morris

Hi Pho,
I have heard the term Functor used like that before. Also, I have seen a discussion on the Scala mailing list about it. FYI, I call it a misuse and so do many others, but let's not get hung up on that.

Instead, here is a more concise definition. A functor is any implementation of the following interface:


...such that 2 laws satisfy:
  • identity. forall x. fmap(identity, x) == x
  • composition. forall f g x. fmap(f, fmap(g, x)) == fmap(f compose g, x)


  • Notice the kind of the type constructor argument F (* -> *). There are several type constructors that satisfy this kind. Just to name a few:
  • scala.List
  • scala.Option
  • scala.Stream
  • scala.Either.LeftProjection
  • scala.Either.RightProjection
  • scala.Function1#Apply[T] (i.e. curry the first type argument)


  • You might be keen to implement this interface with these type constructors just to observe each functor manifest

    15 years ago
    You are mixing lazy evaluation with side-effects, which is a big no-no. As you have observed, reasoning about the correctness of your program becomes difficult.
    15 years ago
    Garrett, Look up "Abstract Algebraic Data Types". The use of an abstract ADT will resolve your issue.
    15 years ago