Type Driven Development with Idris
Sample code and exercise solutions from "Type Driven Development with Idris", available from https://www.manning.com/books/type-driven-development-with-idris
Sample code from "Type Driven Development with Idris"
License: MIT License
Sample code and exercise solutions from "Type Driven Development with Idris", available from https://www.manning.com/books/type-driven-development-with-idris
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
In this example, https://github.com/edwinb/TypeDD-Samples/blob/master/Chapter2/AveMain.idr, entering ^D just cause an infinite stream of "Enter a string: The average word length is: nan". Is this expected or a bug?
I expect it to show "Enter a string: The average word length is: nan" just once.
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)
in line 91,
do Just x <- GetInput | Nothig => do Display "Invalid input"
Nothig -> Nothing
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
TypeDD-Samples/Chapter6/Printf.idr
Line 27 in a5c08a1
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
?
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.