F#使用地图解密类型 [英] F# Deciphering a type with maps

查看:59
本文介绍了F#使用地图解密类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是从F#开始,我想知道如何从书籍示例中解读以下类型及其代表的含义:

I'm just starting out in F# and I'm wondering how to decipher the following types and what they represent from a book example:

type subs = Map<string,exp> option

type lp = (subs->subs) ->subs->subs // A LP computation

我知道子类型只是带有字符串和关联的exp类型的映射...但是我不理解'->'的使用以及lp类型的赋值是什么...

I understand the sub type is simply a map with strings and an associated exp type... but I dont understand the use of '->' and what the lp type is assigning...

任何解密lp类型的帮助都很好

Any help on deciphering the lp type would be great

推荐答案

->表示一个函数.例如,string -> int表示一个函数,该函数将字符串作为参数,并返回一个整数.

The -> represents a function. For example, string -> int represents a function that takes a string as an argument, and returns an integer.

如果链接->,则从右到左读取:a -> b -> c -> da -> (b -> (c -> d)).

If you chain the ->, you read it from right to left: a -> b -> c -> d is a -> (b -> (c -> d)).

函数可以将函数作为参数,因此lp(subs -> subs) -> subs -> subs,也写为(subs -> subs) -> (subs -> subs).它是一个具有功能的功能. 如果令人困惑,请尝试将其视为fn -> (subs -> subs),其中type fn = subs -> subs是函数的类型.

Functions can take functions as arguments, so, lp is (subs -> subs) -> subs -> subs, which is also written as (subs -> subs) -> (subs -> subs). It is a function that takes a function. If it is confusing, try to see it as fn -> (subs -> subs), where type fn = subs -> subs, a type for a function.

另请参见: http://en.wikipedia.org/wiki/Higher-order_function

这篇关于F#使用地图解密类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆