2つの引数の数字を比較して大きい方をx小さい方をyに入れて返すという関数をhaskellのif文で実装したいと考えています。引数1つのサンプルを参考にして下記を作成したのですが else temp=x x=y y=temp ---------- ^ Failed, no modules loaded. temp=xで上記のようなエラーが出ます. おそらく書き方が間違えていると予想しているのですが、どこが間違えているかわかりません。教えてください。 haskell
これはHaskell Advent Calendar 2023の19番目の記事です。 フォーマッター 以前、フォーマッターをいくつか試しましたが、どれもイマイチでした。しかし、fourmoluはいけてます。fourmoluは、Ormoluのフォークで、Ormoluが偉大なのでしょう。両方試しましたが、僕はformoluに決めました。 Hackageに上がっているので好きな方法でインストールしてください。 % cabal install fourmolu formoluにHaskellのプログラムを渡すと、整形したプログラムを出力してくれます。ファイルの内容を直接書き換えたいときは、-iオプションを渡します。エディタやIDEと連動できますが、お試しでプロジェクト全体を整形するには、以下のようにするといいでしょう。 % find . -name "*.hs" | xargs fourmolu
A short write-up on combining digraphs, a feature built-in to vim, and Haskell's UnicodeSyntax extension, to easily write beautiful Haskell programs with unicode symbols. #haskell#vim 1 Haskell’s Unicode Syntax Extension Haskell (well, GHC Haskell) features an extension called UnicodeSyntax. When enabled, this extension allows the use of certain unicode symbols in place of their corresponding keyw
A toy compiler for a subset of JavaScript to ARM assembly, using Haskell. Published: May 29, 2022 I recently got a copy of the book Compiling to Assembly from Scratch by Vladamir Keleshev, which details how to write a compiler for a subset of JavaScript to 32-bit ARM assembly code. The choice to use ARM assembly is mainly for its simplicity in comparison to x86. Keleshev elects to use TypeScript t
描けた! pic.twitter.com/3h0Jtmlw7U — 🌌S.Percentage🙀 (@Pctg_x8) September 15, 2020 リポジトリはこちら: https://github.com/Pctg-x8/haskell-d3d12-test HaskellのFFI 今回はDirectX12に主軸をおいた記事ではないため、DirectX12の初期化の方法などは解説しません。他の記事をご参照ください。 Haskellも実用的なプログラミング言語の例に漏れず、C言語など他の言語とのインターフェイス(FFI)の仕組みを持っています。 Haskellのそれはかなり「低レベル」かつ「なんでもあり」な感じになっています。 HaskellのFFIの詳細については他の記事を参照してもらうとして、大雑把には以下のような形でインターフェイスが提供されています。 基本データ型 F
This is the first of the two parts of our Parsing with Haskell series. Looking for the second part instead? You can find it here. This two-part tutorial will look into two tools often used together by Haskellers to parse programs: Alex and Happy. We’ll use them to parse a small programming language from scratch. Both Alex and Happy are industrial-strength tools powerful enough to parse even Haskel
Create a Windows installer for your Haskell projectIn this blog post, I’ll try to explain how you can create a really simple installer for your Haskell software on Windows and how to deal with external dependencies. IntroductionAlright, let’s get started. We are going to build a simple installer. It will install a desktop shortcut as well as a link shortcut in the start menu. We will be using Stac
Tweet 🎅この記事は、Haskell Advent Calendar 2020 25日目の記事です。 🎄Happy Christmas!!🎄 今回は先日(といっても元の質問の投稿からもう何ヶ月も経ってしまいましたが…)StackOverflowに上がったこちら👇の質問に対する回答の、続きっぽい話を書こうと思います。長いし、質問の回答からスコープが大きく外れてしまうので記事にしました。 haskell - モナド則を崩してしまう例が知りたい - スタック・オーバーフロー MonadとMonoidにある重要な繋がりを説明した後、それを応用したWriter MonadがどうMonoidを使ってMonad則を満たしているのか証明します。そして、Writerのそうした性質を用いて簡単にMonad則を破る例を紹介することで、読者のみなさんがMonad則のみならずdo記法やMonadそのもの
Exceptions kind of suck in Haskell. You don’t get a stack trace. They don’t show up in the types of functions. They incorporate a subtyping mechanism that feels more like Java casting than typical Haskell programming. A partial solution to the problem is HasCallStack - that gives us a CallStack which gets attached to error calls. However, it only gets attached to error - so you can either have Str
This blogpost describes a DoS vulnerability in Haskell's aeson package. We have followed appropriate procedure for responsible disclosure but the problem was not fixed, so now we are releasing this to the public in the hope that it may still be fixed afterall. Disclaimer: This story is the result of a team effort at FP Complete in 2018. I have received explicit written permission to post it here.
tldr: Announcing Ema, a new static site generator in Haskell with hot reload destined to develop an unique kind of apps. This post mostly goes over the background of choosing to create it. A little over a year ago I created the rib static site generator in Haskell based on Shake and ghcid. The idea was to be able to write a more intuitive (so no Makefile-like rules) set of instructions for buildin
久しぶりに(10年ぶりに?)Haskell書きたくなったので環境構築していく。 TS がふわふわ言語仕様過ぎて、AIに好きに書かせると崩壊する。コンパイルの難易度が高くても型の表現力が高いHaskellでどこまでやれるかをテストしたい。 (今回 Rust でないのは、システムレベルではない意味論抽象に主にフォーカスしたいから。 具体的には Extensible Effects を使いたい) 初手でこういうプロンプトを書いた。 私は haskell のエキスパートで、ユーザーに haskell の使い方を教えながらコードを書きます。 ユーザーは TypeScript のエキスパートで、多少のRustの知識があります。Haskell は初心者です。 このプロジェクトは最新の cabal でセットアップされています。 stack を使わず、 cabal のみを使ってビルドと依存関係の管理を行いま
There are two different ways to compile MicroHs: Using GHC. Makefile target bin/gmhs Using the included combinator file and runtime. Makefile target bin/mhs These different ways of compiling need slightly different imports etc. This happens by GHC looking in the ghc/ subdirectory first for any extras/overrides. Compiling MicroHs is really best done using make, but there is also a MicroHs.cabal fil
Sum and Product Types -�The Fruit Salad & Fruit Snack Example - From F# to Haskell, Scala and Java - The document describes how product types (built using AND) and sum types (built using OR) are used to define types for representing fruit salads and fruit snacks in F#, Haskell, Scala, and Java. - Product types combine elements and are used to define the FruitSalad type, while sum types allow alter
In today's article, I will showcase how Haskell's typesystem can be used to simplify code generation and reduce the chance of bugs involving the LLVM getelementptr instruction. Intro to the GEP instruction LLVM as a compiler framework offers many different low-level instructions, one of which being the getelementptr instruction (commonly abbreviated as just "gep"). With gep, you can compute derive
Dependent types are a hot topic in the Haskell community. Many voices advocate for adding dependent types to Haskell, and a lot of effort is being invested towards that end. At the same time, the sceptics raise various concerns, one being that dependent types are more of a research project than a tool applicable in industrial software development. That is, however, a false dichotomy. While depende
Haskell で依存型を扱う方法について勉強したのでメモを残しておきます。 承前 この記事では要素数つきリスト Vect の実装を例に Haskell で依存型を扱うために必要な知識のごく基礎的な部分についてまとめます。ただし、目指すのは Vect を ある程度 開発できる体制を整えることで、十分に開発できる体制は目指しません。というのは、依存型に関わる知識はそれなりに広大で、全てを収めると記事が非常に長くなってしまい、私の精神衛生上良くないことが起こるためです。 この記事では、Haskell での依存型の開発において必要な知識のうち、証明に関するもの以外を一通り揃えることを目指しますが、個人がひっそりと勉強しながら書き進めたもののため、完全な情報となるかは甚だ疑問です。そのため、誤りや欠落等を発見した場合はご指摘いただけると助かります。 なお、この記事が想定する読者は、Haskell
Haskellにはfor文もwhile文もありません。 大抵の場合はmap, filter, foldrのような関数を使えば事足りますし、再帰関数を使えばほとんどのループ処理は書けてしまいます。しかし時には今考えているループを実装するために適切な高階関数が思いつかなかったり、計算結果だけが欲しいのに再帰関数をわざわざ定義するのが煩わしくなったりする状況もあるでしょう。 "グラフからコミュニティ構造を抽出する 〜リッチフローによるグラフの時間発展〜"を書いた時にいくつかループ処理を実装する必要があって、その度に再帰関数を定義するのが大変だったので flip fix を使いました。そして思ったより flip fix の使い勝手が良かったので、この記事ではこれにスポットライトを当てて紹介したいと思います。
2022-05-29 I just wanted to share some of my favorite Haskell libraries, and why I love them. Most of my projects use most of these libraries. relude: Alternative PreludeMore convenient Re-exports common types, type classes, and functions from base, containers, text, bytestring, etc. Types: Text and LText, ByteString and LByteString, etc. Type classes: Alternative, MonadIO, Generic, etc. Functions
ラムダ計算を分かりやすく説明した本がありました。 「計算モデルとプログラミング」という本です。 計算モデルとプログラミング 作者:猪股 俊光,山田 敬三 発売日: 2019/04/19 メディア: 単行本 本書を参考にして、ラムダ計算の説明方法を学んでみたいと思います。 目次 著者紹介 出版社情報 書評 目次 第1章 計算の世界と計算モデル 1.1 計算の世界 1.2 計算モデル 1.3 計算モデルとプログラミング言語 1.4 アルゴリズムの記法 1.5 数の体系 1.6 自然数上の計算と計算モデル 演習問題 第2章 抽象機械型計算モデル 2.1 機械による計算のモデル化 2.2 順序機械 2.3 有限オートマトン 2.4 チューリング機械 2.5 チューリング機械の計算可能性 2.6 まとめ 演習問題 第3章 命令型計算モデル 3.1 命令による計算のモデル化 3.2 レジスタ機械 3.
2020/7/28に新しいHaskell拡張がリリースされました。 https://marketplace.visualstudio.com/items?itemName=haskell.haskell さっそく、こいつを使って最速開発環境構築していくぜ!!! 前提条件 Dockerをインストール VSCodeをインストール Remote - Containers拡張のインストール コンテナ上でHaskell拡張を動作させる 任意のフォルダに.devcontainer.jsonファイルを作成して以下を記載 { "name": "HaskellDevContainer", // DockerhubのHaskell公式イメージ "image": "haskell:8.8", "extensions": [ // HaskellのVSCode拡張をインストール // https://market
Haskellでは再帰的に定義された関数は遅延評価で計算される。 この遅延評価はHaskellの売りの一つであるが、これが時には仇となる。 たとえば、優雅な実装例で知られる次のフィボナッチ数の実装は遅く、メモリの消費量も多い。 fib n = fibs !! n fibs = 1:1:zipWith (+) fib (tail fib) これは、値が評価されるまで計算が待機してメモリが保持されつづけられることが原因だ。 これを解決するには、遅延評価ではなく正格評価で計算すれば良い。 Haskellの神話 - あどけない話 ではzipWithを正格化したzipWith’を定義して、計算を早くする例が提示されていた。 再帰でループを表現するのは、haskellならではの優雅な実装方法だけども、基本は遅延評価なので今あげた問題がついて回る。 例えば、C言語で old=init for (i=1;
はじめに Haskellは、強い静的型付けを持つ純粋関数型プログラミング言語です。 インストール Haskellの環境は、Haskell PlatformまたはHaskell Stackを使って導入します。 Haskell Platform Haskell Platformをインストールすると、Haskellの処理系(GHC)や周辺ツールを一括で導入することができます。Ubuntuでは、以下のコマンドでHaskell Platformを導入できます。 ただし、この方法で入るHaskell処理系(GHC)はやや古いので、最新のHaskellを使いたい場合は後述するHaskell Stackを導入しましょう。 Haskell Stackのインストール Haskell Stackのインストール手順は次のようになります: apt を使って haskell-stack をインストールする。これによっ
You might already know the map function: map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs > map (\x -> x + 1) [1, 2, 3] [2, 3, 4] It takes a function of type a -> b and applies it to each element of a list. The elements change, but the data type storing them ([]) remains the same. In this article, we’ll call such a data type with another type inside it a context. Transform
Posted on August 4, 2020 by Michail Pardalos As part of my Google Summer of Code project to add instrumentation to ghcide, I needed to measure the size of Haskell values in memory. After getting blocked by a bug in a GHC primop I fell down a rabbit hole of learning about GHC’s memory layout, C– and making my first contribution to GHC. In this post I want to describe that journey and hopefully enco
仕事では Bazel を使ってビルドすることが多くなり,自分でも Bazel ルールを自作するようになったので,実験も兼ねて趣味の Haskell Stack プロジェクトを Bazel を使ってビルドしてみることにしました. 本記事はそのメモ書きです. あとこれは Haskell Advent Calendar 2020 の2日目の記事です. Bazel Bazel は Google のエンジニアが中心になって開発している OSS のビルドツールだ. 以下のような特徴がある: 必要なコマンドのインストール・バイナリのビルド・コマンドの実行などを記述できる それらは全て専用のサンドボックス内で実行されるため再現性が高い Starlark という Python 風な独自言語で記述する キャッシュなどが工夫されており二度目以降のビルドが高速になりやすい 依存関係を明確に記述する必要がある また
Most programming languages have a way to make compound data types. In Haskell, we can do that via algebraic data types. Even though the name might sound scary at first, it’s simply a way to construct types. This article will introduce you to the concept of algebraic data types and show you how to use them. Read further to learn: how to create your own custom Haskell data types; what product and su
Since the inception of the Haskell language, the community around it has steadily innovated with language extensions and abstractions. To mention a few, we had the IO monad, all flavors of type classes and constraints, Template Haskell, generalized algebraic data types (GADTs), data kinds, etc. Then we had to deal with the programs resulting from all this innovation, which eventually sprang feelin
We released a blazingly fast Aho-Corasick implementation, written in Haskell, in 2019. This implementation was based on UTF-16 strings, since Haskell's text library uses that for its internal string representation. However, the most recent major update of text changed its internal string representation from UTF-16 to UTF-8. This is good news for us, since most of our customer’s data is ASCII, this
struct User { let name: String let age: Int } // birthday(user: User(name: "Anton", age: 33)) = User(name: "Anton", age: 34) func birthday(user: User) -> User { // Calls Haskell function... } To support this workflow, we need a way to convert the User datatype from Haskell to Swift, and vice versa. We are going to serialize (most) inputs and outputs of a function. Even though the serialization as
HaskellのData.Mapモジュールにおいて定義されるMap型(連想配列)に関して, 2つのMapのマージを定義するData.Map.Merge.Strict.mergeの使い方が意外と大変だったので共有します. Data.Mapについて こちらの記事に基本的な事項がまとめてあります. Data.Mapの使用にはcontainersパッケージのインストールが必要です. こちらでも言及されている通り非正格なData.Mapは特別な理由がない限り非推奨とのことなので, 本記事でも正格版であるData.Map.Strictを用います. keyの型k, valueの型aの連想配列Map k aは配列[(k,a)]からfromList関数によって生成できます:
We’re running Haskell in production. We’ve told that story before. We are also running Haskell in production on Kubernetes, but we never talked about that. It was a long journey and it wasn’t all roses, so we’re going to share what we went through. TL;DRConfigure Haskell RTS settings: Match -N⟨x⟩ to your limits.cpuMatch -M⟨size⟩ to your limits.memoryYou can set them between +RTS ... -RTS arguments
Haskell base proposal: unifying vector-like types Published March 16, 2021 DISCUSSION I've opened up a Discourse thread to discuss this post. I'll likely respond to comments here and on Twitter, but I'd like to move towards using the more official discussion channels when possible. One of my greatest hopes for the Haskell Foundation is already beginning to be realized: better communication. I'm a
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く