SML(裁员数学和功能编程)中的合成
我需要定义一个递归的ML函数组成,该功能组成接受两个关系并返回两个关系的组成。我需要在我的构图定义中使用thhisistheimageof和creterealation -fromimage函数。
这是需要用于定义组成的代码
有趣的是(e,[])= [] | thistheimageof(e,(a,b):: xs)= 如果e = a 然后b :: ThisistheImageOf(e,xs) 否则这是Theistheimageof(e,xs);
这是THISTHEIMAGEOF函数的数据类型,值和测试的输入
数据类型城市=温哥华| Losangeles |墨西哥| Minneapolis | Omaha | Omaha | Kansascity | Kansascity | Denver | Stlouis | Memphis | Memphis |芝加哥| Neworleans | Cinncinati | Pittsburgh | Pittsburgh | pittsburgh | Montreal | Nework | Newyork; 数据类型河=密苏里州| Platte | nplatte | splatte | Arkansas | Canadian |堪萨斯州|密西西比州|田纳西州|俄亥俄州| Allegheny | Monongahela; VAL ISONRIVER = [(丹佛,普拉特),(密苏里州奥马哈),(奥马哈,普拉特),(密苏里州的卡萨西斯,密苏里州),(堪萨斯州,堪萨斯州),(明尼阿波利斯,密西西比州,密西西比州),(stlouis,Mississippi),(Stlouis),(Stlouis,mi vssouri),(孟菲斯,密西西比州),(纽约市,密西西比州),(俄亥俄州的Cinncinati),(俄亥俄州匹兹堡,俄亥俄州),(匹兹堡,阿勒格尼),(匹兹堡,莫农贝拉,蒙加利亚)]; Val FlowWOWSInto = [(密苏里州普拉特),(密苏里州的堪萨斯州),(密苏里州,密西西比州),(俄亥俄州阿勒格尼市),(俄亥俄州的Monongahela,俄亥俄州),(俄亥俄州田纳西州,俄亥俄州),(Nplatte,Platte,Platte,Platte),(Splatte,Platte,Platte,Platte,Platte ),(俄亥俄州,密西西比州)]; Thistheimageof(匹兹堡,Isonriver);这是Thistheimageof(Mississippi,Flowsinto); Thistheimageof(cinncinati,isonriver); Fun Fromimage(E,[])= [] Fromimage(E,X :: XS)=(E,X):: CretereLalationFromimage(E,XS);``````'' 以下是对creteralation -fromimage功能的测试输入
creterelationfromimage(“ cincinnati”,[“纽约”,“波士顿”,“达拉斯”]);
这两个函数是作为单独函数创建的,但我应该使用两个功能来制作组成的递归函数。
我从数学上知道构图功能,这是我所说的,以帮助我看看我需要做的事情
有趣的构图(i,r)x = i(r(x));
但是,在尝试实施这两个功能时,我一直坚持进一步。
I need to define a recursive ML function composition that accepts two relations and returns the composition of the two relations. I need to use the thhisIsTheImageOf and createRelationFromImage function in my definition of composition.
Here is the code that is needed to be used to define the composition
fun thisIsTheImageOf(e,[])=[] |thisIsTheImageOf(e,(a,b)::xs) = if e=a then b::thisIsTheImageOf(e,xs) else thisIsTheImageOf(e,xs);
Here are the datatype, value, and tested inputs for the thisIsTheImageOf function
datatype city =Vancouver|LosAngeles|Mexico|Minneapolis|Omaha |KansasCity|Denver|StLouis|Memphis|Chicago |NewOrleans|Cinncinati|Pittsburgh|Montreal|NewYork; datatype rivers =Missouri|Platte|NPlatte|SPlatte|Arkansas|Canadian |Kansas|Mississippi|Tennessee|Ohio|Allegheny|Monongahela; val isOnRiver=[(Denver,Platte),(Omaha,Missouri),(Omaha,Platte),(KansasCity,Missouri),(KansasCity,Kansas),(Minneapolis,Mississippi),(StLouis,Mississippi),(StLouis,Mi vssouri),(Memphis,Mississippi),(NewOrleans,Mississippi),(Cinncinati,Ohio),(Pittsburgh,Ohio),(Pittsburgh,Allegheny),(Pittsburgh,Monongahela)]; val flowsInto=[(Platte,Missouri),(Kansas,Missouri),(Missouri,Mississippi),(Allegheny,Ohio),(Monongahela,Ohio),(Tennessee,Ohio),(NPlatte,Platte),(SPlatte,Platte),(Ohio,Mississippi)]; thisIsTheImageOf(Pittsburgh, isOnRiver);thisIsTheImageOf(Mississippi, flowsInto);thisIsTheImageOf(Cinncinati, isOnRiver); fun createRelationFromImage(e,[])=[] createRelationFromImage(e,x::xs)= (e,x)::createRelationFromImage(e,xs);`` Here are tested inputs for the createRelationFromImage function
createRelationFromImage("Cincinnati",["New York", "Boston", "Dallas"]);
These two functions were created as a separate function but I am supposed to use the two functions to make a recursive function of composition.
I know the composition function mathematically and here is what I put as to help me see what I need to do
fun composition( i, r)x=i(r(x));
however, I am stuck on going further when trying to implement the two functions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)