agrafix / agrafix/elm-bridge

Support for simple phantom types

未關閉
#35 17 則留言 3 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Elm
星號
107
分支
28
PR 合併指標
30 天內沒有已合併 PR

描述

Currently, if we have a simple phantom type like this in Haskell:

```haskell
newtype Id a = Id { unId :: Text }
```

there exists a valid elm equivalent of:

```elm
type Id a = Id { unId : String }
```

However, trying to derive it with `deriveElmDef` fails with the error message:

```
Oops, can only derive data and newtype, not this: NewtypeD [] Main.Id [KindedTV a_6989586621679074905 StarT] Nothing (RecC Main.Id [(Main.unId,Bang NoSourceUnpackedness NoSourceStrictness,ConT Data.Text.Internal.Text)]) []
```

Redefining the initial definition of `Id` to use `data` instead of `newtype` and passing in a dummy type in the `DefineElm` clause like `DefineElm (Proxy @(Id Text))` will produce the following elm code which is invalid:

```elm
type alias Id a =
{ unId: String
}
```

and fails with the error message:

```
Type alias `Id` cannot have unused type variables: a

12|>type alias Id a =
13|> { unId: String
14|> }

You probably need to change the declaration like this:

type alias Id = ...
```
---

What is the current best strategy for sharing simple phantom types across Haskell and Elm?

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。