Coder Social home page Coder Social logo

educationalprelude's Introduction

educationalprelude's People

Contributors

waddlaw avatar

Watchers

 avatar  avatar

educationalprelude's Issues

1 + 0.1 が計算できない問題

ghci> 1 + 0.1
<interactive>:1:5: error:
     Couldn't match expected type Int with actual type Double
     In the second argument of (+), namely 0.1
      In the expression: 1 + 0.1
      In an equation for it’: it = 1 + 0.1

期待する動作

ghci> 1 + 0.1
1.1

implement test

目的

  • ghci で出力する型情報 (:t を行った結果) について単体テストを行いたい。

方針

  • GHC-API を使う
  • diff とる

defaulting で Integer が優先される問題

デフォルトでは

-- Use [Integer, Double], plus modifications
default (Integer, Double)

となっている。変更しようとしても、そのあとの順番しか決めれないため GHC いじるしかない。

数列の扱い

ghci> [0.1, 0.3 .. 1]

<interactive>:66:14: error:
     Couldn't match expected type Double with actual type Int
     In the expression: 1
      In the expression: [0.1, 0.3 .. 1]
      In an equation for it’: it = [0.1, 0.3 .. 1]

期待する動作

ghci> [0.1, 0.3 .. 1]
[0.1,0.3,0.5,0.7,0.8999999999999999,1.0999999999999999]

エラーメッセージに型クラスの情報が出てしまう問題

例えば以下のような感じ。

*EducationalPrelude> 1 == 'a'

<interactive>:13:1: error:
    • No instance for (P.Num Char) arising from the literal ‘1’
    • In the first argument of ‘(==)’, namely ‘1’
      In the expression: 1 == 'a'
      In an equation for ‘it’: it = 1 == 'a'

エラーメッセージを 型が合っていません という感じのシンプルな内容に修正してしまえば良い気がしている。

型クラスの変数を書き換えたい

ghci> :t (^)
Num a => a -> Int -> a

現状は以下のように表示される。

ghci> :t (^)
a -> Int -> a

Bool 型などはこれに当てはまらないが、クラス制約を非表示にしているため、このようになっている。

どうやって実現するか?

  1. MyPrelude を定義する
  2. MyGHCi を実装する
  3. vanilla GHC を実装する

とりあえず MyPrelude を定義する 方向で進めることにした。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.