PureScriptのFFI
PureScriptのFFI
JavaScriptのコードを呼び出す
実装はJSで型だけpsで定義されているpackageも割といっぱいあるmrsekut.icon
docs
guide
かんたんな例
code:./readline.js
"use strict";
var readlineSync = require('readline-sync')
exports.readLine = function () {
return readlineSync.question('user> ')
}
code:./Readline.purs(hs)
module Readline where
import Effect (Effect)
foreign import readLine :: Effect String
expors.hogeの部分と、foreign import hogeの部分の名前を合わせないとコンパイルエラーになるmrsekut.icon
新たなkindを定義する
hsでのDataKindsのようなものをforeign import dataで定義する
ref
code:purs(hs)
foreign import data Frob :: Type
foreign import data UseState :: Type -> Type -> Type
https://gyazo.com/2e77c0b5859fb7e03eabddb7eb1e3d33
実際のsyntax hilight
#??
型の付け方
例えば間違った型を付けることもできるのか
できる.
tsの型定義と同じ感じ
手順
ディレクトリ
js側のexport
purs側のimport
カリー化
jsの多引数関数をどうやってカリー化してpursの世界に持ってくるのか
https://qiita.com/pab_tech/items/0eb43d73c135d93fa09c#purescript-functions
この記事はめちゃくちゃ古いので参考程度に
https://github.com/purescript/purescript-functions
JSのnullの扱い
https://qiita.com/pab_tech/items/0eb43d73c135d93fa09c#purescript-nullable
この記事はめちゃくちゃ古いので参考程度に
副作用の扱い
https://qiita.com/pab_tech/items/0eb43d73c135d93fa09c#javascriptの関数が副作用を持つ場合のffiの書き方の注意点
この記事はめちゃくちゃ古いので参考程度に
JSのthisの扱い
https://qiita.com/pab_tech/items/0eb43d73c135d93fa09c#purescript-eff-functionsでjavascriptのthisの問題を解決する
この記事はめちゃくちゃ古いので参考程度に
関連
purescript-tsd-gen
https://github.com/minoki/purescript-tsd-gen
TSの型定義ファイルをpursに使う
https://purescript-resources.readthedocs.io/en/latest/ffi.html
https://qiita.com/matoruru/items/a77c4d10c15a806d894a
https://book.purescript.org/chapter10.html
https://github.com/purescript/documentation/blob/master/guides/FFI.md
https://github.com/purescript/purescript-foreign
https://aratama.github.io/purescript/chapter10.html
https://qiita.com/kimagure/items/b0b7da07d8183cb51d58
https://qiita.com/kimagure/items/0ce4d9d2792dd110ee45