https://github.com/wolfadex/elm-haskell-cheat-sheet
Reminders when moving between Elm and Haskell
https://github.com/wolfadex/elm-haskell-cheat-sheet
Last synced: 4 months ago
JSON representation
Reminders when moving between Elm and Haskell
- Host: GitHub
- URL: https://github.com/wolfadex/elm-haskell-cheat-sheet
- Owner: wolfadex
- Created: 2021-02-17T00:22:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-05T17:17:23.000Z (over 4 years ago)
- Last Synced: 2025-04-02T03:24:12.471Z (about 1 year ago)
- Size: 8.79 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Elm <-> Haskell Cheat Sheet
### _and other tidbits_
A collection of operators and other things I forget when going between Elm and Haskell.
| Elm | Haskell | Notes |
| ----------------------------------------------- | ------------------------------------------- | -------------------------------------------------------------------------------------- |
| Type.map | fmap _or_ <$> | modify the inner value |
| Type.andThen | >>= | return a new `Type` from the inner value |
| \x -> x / 2 | (/ 2) | The Elm version is a little more clear |
| a :: rest | a : rest | cons |
| func : a -> b | func :: a -> b | func name and type separator |
| func : number -> number | func :: Number a => a -> a | type classes |
| <\| | $ | |
| \|> | & | |
| << | . | |
| >> | .> | requires the [flow](https://hackage.haskell.org/package/flow) package |
| | | |
| ++ | <> | |
| Type.andMap | <\*> | `andMap :: f (a -> b) -> f a -> f b` |
| | <\|> | Alternative aka `a <\|> b` aka `a or b` |
| import My.Module as X exposing (func, Type(..)) | import My.Module as X | |
| | import My.Module (func, Type(..)) | |
| | import qualified My.Module | The default Haskell import is equivalent to `import My.Module exposing (..)` in Elm. |
| Tuple.pair | (,) | |
| ({ x, y } as point) | point@{x,y}. | |
| Maybe.withDefault | Data.Maybe.fromMaybe | |
| always | const | |
| { record \| field1 = value1, field2 = value2 } | record { field1 = value1, field2 = value2 } | |
| record.field | record.field | If you have RecordDotSyntax language extension enabled in Haskell |
| .field record | field record | |
| ({ field } as record) | record@RecordConstructor {field} | |
---
### Haskell:
Type class definition and implementation
```Haskell
-- Create a type class
class Eq a where
(==) :: a -> a -> Bool
-- My custom type
data MyWrapper = MyWrapper String
-- Implementing `Eq` for my custom type
instance Eq MyType where
(==) (MyWrapper a) (MyWrapper b) = a == b
```