Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create asking for type #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions asking for type
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import Data.Functor


g :: _
g = "greetings upon you"

-- Compiler says:

-- Found type wildcard ‘_’ standing for ‘[Char]’
-- In the type signature: g :: _



f :: _ -> Bool
f x = not x

-- Compiler says:

-- Found type wildcard ‘_’ standing for ‘Bool’
-- In the type signature: f :: _ -> Bool



sum :: [Int] -> Int
sum xs = foldr _f _x xs

-- Compiler says:

-- Found hole: _f :: Int -> Int -> Int
-- Or perhaps ‘_f’ is mis-spelled, or not in scope
-- • In the first argument of ‘foldr’, namely ‘_f’
-- In the expression: foldr _f _x xs
-- In an equation for ‘Main.sum’: Main.sum xs = foldr _f _x xs
-- • Relevant bindings include
-- xs :: [Int] (bound at filename.hs:22:5)
-- sum :: [Int] -> Int (bound at filename.hs:22:1)
-- Valid substitutions include
-- undefined :: forall (a :: TYPE r).
-- GHC.Stack.Types.HasCallStack =>
-- a

-- (*) :: forall a. Num a => a -> a -> a

-- (+) :: forall a. Num a => a -> a -> a

-- Found hole: _x :: Int
-- Or perhaps ‘_x’ is mis-spelled, or not in scope
-- In the second argument of ‘foldr’, namely ‘_x’
-- In the expression: foldr _f _x xs
-- In an equation for ‘Main.sum’: Main.sum xs = foldr _f _x xs
-- Relevant bindings include
-- xs :: [Int] (bound at filename.hs:22:5)
-- sum :: [Int] -> Int (bound at filename.hs:22:1)



-- One can use the compiler to get hints about some code
data Tree a = Leaf a | Node (Tree a) (Tree a)

instance Functor Tree where
fmap f (Leaf a) = Leaf (f a)
fmap f (Node l r) = Node (_ f l) (_ f r)

-- Compiler says:

-- Found hole: _ :: (a -> b) -> Tree a -> Tree b
-- Valid substitutions include
-- fmap :: forall (f :: * -> *).
-- Functor f =>
-- forall a b. (a -> b) -> f a -> f b