Changes between Version 2 and Version 3 of Holes


Ignore:
Timestamp:
Feb 9, 2012 8:54:48 PM (4 years ago)
Author:
xnyhps
Comment:

More about ranges, made examples consistent

Legend:

Unmodified
Added
Removed
Modified
  • Holes

    v2 v3  
    100100{{{
    101101test :: [Bool]
    102 test = __ : __ : []
     102test = __ : (__ ++ [])
    103103}}}
    104104Theoretical output:
     
    107107[1 of 1] Compiling Main             ( test.hs, interpreted )
    108108Found a hole at test.hs:2:6-7: Bool
    109 Found a hole at test.hs:2:11-12: Bool
     109Found a hole at test.hs:2:12-13: [Bool]
    110110>
    111111}}}
     
    118118{{{
    119119test :: [Bool]
    120 test = _a : _b : []
     120test = _a : (_b ++ [])
    121121
    122 test2 = (_a, _b)
     122test2 = _c ++ _b
    123123}}}
    124124Theoretical output:
     
    127127[1 of 1] Compiling Main             ( test.hs, interpreted )
    128128Found a hole _a: Bool
    129 Found a hole _b: Bool
     129Found a hole _b: [Bool]
     130Found a hole _c: [Bool]
    130131>
    131132}}}
     
    134135
    135136=== Not holes, ranges ===
    136 Holes can be useful for finding the type of something that still needs to be written, but it's also possible one might want to figure out the type of a part of an existing expression. For example, a user could be trying to understand a big, complicated function he didn't write himself, and trying to figure out what the types are of certain parts of that function could involve a lot of looking up of other functions.
     137Holes can be useful for finding the type of something that still needs to be written, but a more general way of looking at it is this: it is currently quite easy to typecheck a complete expression, for example with {{{:t}}}, in GHCi. However, finding the type of a part of an expression within a module is hard. In a large, complicated function it could be useful to ask the compiler for the types subexpressions. {{{:t}}} does not help here, as the function's parameters and where/let/lambda-bound terms are not in scope. It would be useful if it were possible to annotate code to ask the compiler to give you the type found for it.
     138
     139Simple example (let {{{{_ _}}}} denote a request for the type here):
     140{{{
     141test :: [Bool]
     142test = {_ undefined _} : ({_ undefined ++ [] _})
     143}}}
     144
     145Could result in:
     146{{{
     147> :l test.hs
     148[1 of 1] Compiling Main             ( test.hs, interpreted )
     149Found type of undefined (test.hs:2:11-19): Bool
     150Found type of undefined ++ [] (test.hs:2:30-38): [Bool]
     151}}}
     152
     153The same effect of holes can then be achieved by using {{{ {_ undefined _} }}}.