Comments (2)
I totally agree that the HS style type signatures are nicer to read. But I think that this is highly subjective.
I think even if it could be mapped 100% percent it's hard to justify why adding a second notation to the existing on of the language we use. 95% mapping also really depends, I'd say there's a much larger portion of signatures that cannot be mapped.
Think of "mapped types" {[key in keyof ..]: ...}
, indexed types Foo["bar"]
, conditional types foo extends bar ? baz : boo
and many more.
One of the biggest annoyance for me was that parameter's have to be named in signatures. However, they have a semantic meaning, as they can be referenced inside the type signature. E.G. this is a valid type: type T = <T,A>(y : A, x: T & A) => typeof x
The benefit of it may be questioned, but still it's something that would have to be mapped.
Regarding your example, in PureScript I think it's ok in this case to combine a
and e
in one forall
in the beginning. In TS that would be not valid, as the E would be inferred as unknown after the application of the first argument. What if for some reasons I explicitly want const f: <A, E>(a: A) => <E>(b: ....
? That would be hard to distinguish in the suggested mapping.
In my view, this raises many many questions. But as I said, I can totally understand the intend. Once I thought that Fn<A,B> = (x: A) => B
and then having Fn2
, Fn3
etc. would make signatures easier to read but in the end I also dropped that and accepted the existing signatures :)
from docs-ts.
I wanted to learn how to write a parser in Haskell so I've written this over the last two weeks. I'm still working on it, but it already covers probably 95% of type signatures, and the CLI returns an appropriate exit code so it should be possible to use it conditionally, not outputting an alternative style type signature where the TypeScript declaration syntax is currently unsupported.
tshm, example usage:
$ tshm "export declare const f: <A>(a: A) => <E>(b: Either<E, Option<A>>) => A"
f :: forall a e. a -> Either e (Option a) -> a
$ tshm "export type Option<A> = None | Some<A>"
type Option a = None | Some a
I'm going to see if I can integrate it into fp-ts-std shortly.
Edit: It's now implemented in the develop branch. At the moment I'm just - in a very hacky way - parsing the markdown produced by docs-ts and appending the tshm signatures wherever it recognises any.
Edit 2: Now used across fp-ts-std documentation.
from docs-ts.
Related Issues (20)
- [discussion] Why use ts-morph over tsc? HOT 3
- Error when compiling docs HOT 2
- `@types/node` is needed HOT 2
- Horizontal scrolling in rendered code blocks HOT 4
- @example imports still buggy HOT 1
- Incorrect return type for `toNullable` and `toUndefined` HOT 1
- "Missing examples" when examples are enforced in fp-ts-std HOT 10
- View rendered docs locally HOT 4
- Omit `.ts` in sidebar HOT 2
- Can't ignore private methods from being generated HOT 1
- Enforcement exclusions HOT 4
- Modules with only exports from other modules result in empty ToC
- Feature request: Forward options to ts-morph
- ts-morph needs updating
- tsx support
- "Why" section of the readme seems incomplete HOT 1
- Consider migrating to vitepress
- Bug: getter documentation is skipped
- Document how to make use of & debug the example type checking? HOT 2
- Prettier as peer dependency prevents upgrading it in consumers projects HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs-ts.