agrafix / agrafix/elm-bridge

How to deal with # (magic hash) in Haskell data types?

Aberta
#51 2 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Elm
Estrelas
107
Forks
28
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

I started to learn about Servant from the [Building an API with Servant!](https://mmhaskell.com/real-world/servant) tutorial. When I later got interested in Elm I tried to automatically generate Elm code for this Servant API which uses `Int64` and I discovered that `Int64` is [defined](https://hackage.haskell.org/package/base-4.16.0.0/docs/src/GHC.Int.html#I64%23) as a primitive unboxed Haskell type:

data {-# CTYPE "HsInt64" #-} Int64 = I64# Int#

, which make use of `#` ([magic hashes](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/magic_hash.html)).

In the generated Elm module the Haskell type `Int64` is represented by the following Elm type:

type Int64 =
I64# Int#

, which is not valid Elm syntax:

-- UNEXPECTED SYMBOL /Users/XXX/elm-frontend/src/Derived.elm

I got stuck on this symbol:

14| I64# Int#
^
It is not used for anything in Elm syntax. Try removing it?

I've initially posted a [question on Stack Overflow](https://stackoverflow.com/questions/69937285/using-servant-elm-and-elm-derive-with-int64-deriving-and-generating-definition) about this. The obvious solution is to simply avoid data types with magic hashes in the Servant API. But, even if Elm may not have an analogue to boxed vs unboxed types, I cannot help wondering if it wouldn't be useful to be able to generate Elm code for arbitrary Servant APIs including data types with magic hashes. In this example, if the ranges of Haskell `Int` and Elm `Int` are the same, the magic hashes could simply be removed and the Haskell `Int#` be represented by `Int` in Elm:

type Int64 =
I64 Int

There may be more to this topic than I currently understand and there are probably a lot to consider to make this work for all general uses of magic hashes in Haskell data types. Anyway, since I stumbled upon this I thought I should create a GitHub issue.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.