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);
  • 相关阅读:
    寒假作业1
    自我介绍
    我罗斯方块1
    我罗斯方块
    解题报告 数学2
    解题报告 转化模式
    解题报告 数学
    经典语录
    解题报告 Trick
    解题报告 帮忙
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10416213.html
Copyright © 2011-2022 走看看