zoukankan      html  css  js  c++  java
  • [Functional Programming] Function signature

    It is really important to understand function signature in functional programming.

    The the code example below:

    const map = fn => anyFunctor => anyFunctor.map(fn);

    'map' is pointfree version of any founctor's map, for example:

    Maybe.of('maybe').map(toUpper)

    equals:

    compose(map(toUpper), Maybe.of)('maybe') // Just 'MAYBE'

    So what is the function signature for 'map'?

    fn: is a function, we can use 

      (a -> b) : We read it as "A function which take a to b"

    anyFunctor: is a Functor, any Functor, we can use:

      f a:  here 'f' means Functor, 'a' means 'any value': We read it as 'Any functor a'

    anyFunctor.map(fn): is what the return value, it is also a Functor, value may different from 'a':

      f b: here 'f' means Functor, 'b' means 'any value but not the same as 'a' '.

    Here we want to point out 'f' is Functor, we can do: 'Functor f =>'

    // map :: Functor f => (a -> b) -> f a -> f b

    This is the whole result:

    // map :: Functor f => (a -> b) -> f a -> f b
    const map = fn => anyFunctor => anyFunctor.map(fn);
  • 相关阅读:
    ZooKeeper详解
    数据结构与算法2——数组
    jquery复习笔记
    关于水平居中
    回顾这些日子
    阻止事件冒泡
    css导航栏
    js正则
    js事件绑定
    操作iframe
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10416213.html
Copyright © 2011-2022 走看看