@@ -5,19 +5,18 @@ import { isFunctionNode, makeFunctionNode } from '../function-node.js'
55import {
66 isObjectNode ,
77 lookupPropertyOfObjectNode ,
8- makeObjectNode ,
98 type ObjectNode ,
109} from '../object-node.js'
1110import { isSemanticGraph , type SemanticGraph } from '../semantic-graph.js'
1211import { types } from '../type-system.js'
1312import {
1413 makeFunctionType ,
15- makeObjectType ,
1614 makeTypeParameter ,
1715} from '../type-system/type-formats.js'
1816import {
1917 preludeFunction ,
2018 serializeOnceAppliedFunction ,
19+ serializeTwiceAppliedFunction ,
2120} from './stdlib-utilities.js'
2221
2322const A = makeTypeParameter ( 'a' , { assignableTo : types . something } )
@@ -75,66 +74,58 @@ export const globalFunctions = {
7574 ) ,
7675 ) ,
7776
78- // { 0: a => b, 1: b => c } => (a => c)
77+ // (b => c) => (a => b) => (a => c)
7978 flow : preludeFunction (
8079 [ 'flow' ] ,
8180 {
82- parameter : makeObjectType ( '' , {
83- 0 : makeFunctionType ( '' , {
84- parameter : A ,
85- return : B ,
86- } ) ,
87- 1 : makeFunctionType ( '' , {
88- parameter : B ,
89- return : C ,
90- } ) ,
91- } ) ,
92- return : makeFunctionType ( '' , {
93- parameter : A ,
94- return : C ,
95- } ) ,
81+ // TODO
82+ parameter : types . something ,
83+ return : types . something ,
9684 } ,
97- argument => {
98- if ( ! isObjectNode ( argument ) ) {
85+ secondFunction => {
86+ if ( ! isFunctionNode ( secondFunction ) ) {
9987 return either . makeLeft ( {
10088 kind : 'panic' ,
101- message : '`flow` must be given an object ' ,
89+ message : 'argument must be a function ' ,
10290 } )
10391 } else {
104- const argument0 = lookupPropertyOfObjectNode ( '0' , argument )
105- const argument1 = lookupPropertyOfObjectNode ( '1' , argument )
106- if ( option . isNone ( argument0 ) || option . isNone ( argument1 ) ) {
107- return either . makeLeft ( {
108- kind : 'panic' ,
109- message :
110- "`flow`'s argument must contain properties named '0' and '1'" ,
111- } )
112- } else if (
113- ! isFunctionNode ( argument0 . value ) ||
114- ! isFunctionNode ( argument1 . value )
115- ) {
116- return either . makeLeft ( {
117- kind : 'panic' ,
118- message : "`flow`'s argument must contain functions" ,
119- } )
120- } else {
121- const function0 = argument0 . value
122- const function1 = argument1 . value
123- return either . makeRight (
124- makeFunctionNode (
125- {
126- parameter : function0 . signature . parameter ,
127- return : function1 . signature . parameter ,
128- } ,
129- serializeOnceAppliedFunction (
130- [ 'flow' ] ,
131- makeObjectNode ( { 0 : function0 , 1 : function1 } ) ,
132- ) ,
133- option . none ,
134- argument => either . flatMap ( function0 ( argument ) , function1 ) ,
135- ) ,
136- )
137- }
92+ return either . makeRight (
93+ makeFunctionNode (
94+ {
95+ // TODO
96+ parameter : types . something ,
97+ return : types . something ,
98+ } ,
99+ serializeOnceAppliedFunction ( [ 'flow' ] , secondFunction ) ,
100+ option . none ,
101+ firstFunction => {
102+ if ( ! isFunctionNode ( firstFunction ) ) {
103+ return either . makeLeft ( {
104+ kind : 'panic' ,
105+ message : 'argument must be a function' ,
106+ } )
107+ } else {
108+ return either . makeRight (
109+ makeFunctionNode (
110+ {
111+ // TODO
112+ parameter : types . something ,
113+ return : types . something ,
114+ } ,
115+ serializeTwiceAppliedFunction (
116+ [ 'flow' ] ,
117+ secondFunction ,
118+ firstFunction ,
119+ ) ,
120+ option . none ,
121+ argument =>
122+ either . flatMap ( firstFunction ( argument ) , secondFunction ) ,
123+ ) ,
124+ )
125+ }
126+ } ,
127+ ) ,
128+ )
138129 }
139130 } ,
140131 ) ,
0 commit comments