简体   繁体   中英

some Functor type in Dart

In Haskell, some Functor fmap

fmap :: (a -> b) -> f a -> f b

In TypeScript,

type F<A> = A[];
const F = // type constructor
  <A>(a: A): F<A> => [a];

type map = <A, B> // function => function
  (f: (a: A) => B) =>
  (Fa: F<A>) => F<B>;

Similarly, in Dart, I try to implement

typedef F<A> = Map<String, A>;
 
typedef Fmap<A, B> = (F<B> Function(F<A>)) (Function(B Function(A)));

but the second line has errors, what would be the correct syntax?

To be honest I have not the slightest idea what you are trying to do, since I don't get any of the two examples, but this compiles fine:

typedef F<A> = Map<String, A>;

typedef Fmap<A, B> = F<B> Function(F<A>) Function(B Function(A));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM