GithubHelp home page GithubHelp logo

typedd-samples's Introduction

typedd-samples's People

Contributors

edwinb avatar mknoszlig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typedd-samples's Issues

Listing 6.8 `toFormat` '%' case

Hi Edwin,

first of all, thank you for writing such a brilliant book, it's a pleasure to read!

Secondly, I have a question regarding the implementation of toFormat (listing 6.8). It currently goes like this (Chapter6/Printf.idr):

toFormat : (xs : List Char) -> Format
toFormat [] = End
toFormat ('%' :: 'd' :: chars) = Number (toFormat chars)
toFormat ('%' :: 's' :: chars) = Str (toFormat chars)
toFormat ('%' :: chars) = Lit "%" (toFormat chars)
toFormat (c :: chars) = case toFormat chars of
                             Lit lit chars' => Lit (strCons c lit) chars'
                             fmt => Lit (strCons c "") fmt

I don't understand the reason behind the toFormat ('%' :: chars) case. Shouldn't we simply get rid of it and let '%' fall into the final case where it will, if needed, nicely be appended inside a Lit?

For example, given the input "foo%bar", with the implementation in the book, you get:

> toFormat . unpack $ "foo%bar"
Lit "foo%" (Lit "bar" End) : Format

Whereas, when removing the toFormat ('%' :: chars) case, you get:

> toFormat . unpack $ "foo%bar"
Lit "foo%bar" End : Format

I think the latter makes more sense but maybe I am missing something. Happy to open a PR if needed.

Cheers!
Bastien

Can't find implementation of Ord a

I am new to Idris, so forgive me if this a dumb question.

When doing Exercise 5 on page 101 of the TypeDD book, my solution (which is the same as the suggested solution in this repository) exhibits the following behavior when I launch idris ex_4_1.idr:

Type checking ./ex_4_1.idr
*ex_4_1> maxMaybe Nothing Nothing
Can't find implementation for Ord a

According to the definition of maxMaybe (included below for reference), it seems the answer should be Nothing. Is this an error? Do I not have Idris set up correctly?

maxMaybe : Ord a => Maybe a -> Maybe a -> Maybe a
maxMaybe Nothing Nothing = Nothing
maxMaybe Nothing (Just y) = Just y
maxMaybe (Just x) Nothing = Just x
maxMaybe (Just x) (Just y) = Just (max x y)

definition of ProcState in Chapter 15

It's mildly confusing, but in the book, starting from section 15.2.3, the following definition is given:

data ProcState = NoRequest | Sent | Complete

whereas in this repo, ProcessIFace.idr, ProcessLib.idr, ProcessState.idr define it as

data ProcState = Ready | Sent | Looping

How does the inferring work on this line?

printf fmt = printfFmt _ ""

Use an underscore (_) for the format, because Idris can infer from the type that it must be toFormat (unpack fmt).

This's the explanation from the book for above line but I'm still a bit puzzled by how does the inferring work here? Since fmt comes in as a String type, how does it become a Format type when passed to printfFmt?

listing 11.31

In listing 11.31, this:

runCommand (Bind c f) = do res <- runCommand c
                           runCommand (f res)

should be

runCommand (Bind c f) = do res <- runCommand (Pure c)
                           runCommand (f res)

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.