2

I'm trying to understand Ramda docs so I looked up what a functor is here, but what is the ~> in this mean?

map :: Functor f => f a ~> (a -> b) -> f b
stackjlei
  • 9,485
  • 18
  • 65
  • 113
  • There's a short answer at https://stackoverflow.com/questions/43435656, and much, much more detail at https://stackoverflow.com/questions/40361059. – Scott Sauyet Jun 20 '17 at 11:24

1 Answers1

2

It's already written there :

Type signature notation

~> (squiggly arrow) Method type constructor. When a function is a property of an Object, it is called a method. All methods have an implicit parameter type - the type of which they are a property. a ~> a -> a is a type satisfied by methods on Objects of type a which take a type a as an argument and return a value of type a.

Vivek Doshi
  • 56,649
  • 12
  • 110
  • 122
  • if the first `f` is a functor, what is the `f` in front of `a` and `b`? – stackjlei Jun 20 '17 at 05:01
  • The initial bit (`Functor f =>`) is a constrain the the remaining part of the definition. `f` can represent any Functor type, such as lists (really arrays): `map:: [a] ~> (a -> b) -> [b]`, (Note that because lists are so common, there is a shorthand for `Array x`: `[x]`.) Or Maybe: `map: Maybe a ~> (a -> b) -> Maybe b`. or Future: `map :: Future a ~> (a -> b) -> Future b`. Ramda's versions don't deal with *methods*, only *functions*, so these change a bit there, e.g. `map:: (a -> b) -> [a] -> [b]`. But its the same principle. – Scott Sauyet Jun 20 '17 at 11:32
  • 1
    All `f`s represent the same type constructor (or parameterized type). The first appearance of `f` just says that the type constructor `f` has a functor constraint, i.e. instances of `f` must define a suitable `map` operation. What's probably confusing you is that the given type signature just annotates the generic version of this `map` operation. So instances of `f` need a `map` operation and `map` itself expects an instance of `f` as its second argument. –  Jun 20 '17 at 13:28