The hypothetical inCelcius converter scenario assumes that you have had the
misfortune of scraping different web sites for data where you are promised that
it will be easy because everyone uses clean structure ways of presenting their
data. So, it assumes that you have gotten data some of it already numeric,
some in various string formats. That assumption is why I used SCRAPEDATA as
the test noun. Temperature may be a bit artificial, but if there were web
records of Canadian temperatures that went back far enough, some would be in F
before changing over to F.
To answer your isFreezingC application,
0&>: 'inCelcius' c_temperature_ every 44 ;'99F';'7K'; ' _20 Faren.'; '300
Kel.'
0 0 1 1 0
for Farenheit, you can either use:
isFreezingF 'inFaren' c_temperature_ every 44 ;'99F';'7K'; ' _20 Faren.';
'300 Kel.'0 0 1 1 0
isFreezingF 'inCelcius inFaren2' c_temperature_ every 44 ;'99F';'7K'; ' _20
Faren.'; '300 Kel.'
0 0 1 1 0
the latter could also be written 'inCelcius inFaren' but as written is more
efficient because inFaren2 already assumes that it has numbers that were
guaranteed by inCelcius. Its definition is also much simpler than inFaren
because the latter needs to deal with potential strings and various source
formats.
I think too that 'inCelcius inFaren' is better documenting because it explains
that the function uses Fahrenheit but accepts/expects Celcius
Also:
data #~ isFreezingF 'inFaren' c_temperature_ every data =. 44 ;'99F';'7K';
' _20 Faren.'; '300 Kel.'┌──┬───────────┐
│7K│ _20 Faren.│
└──┴───────────┘
----- Original Message -----
From: Joe Bogner <[email protected]>
To: [email protected]
Cc:
Sent: Monday, January 26, 2015 5:53 PM
Subject: Re: [Jprogramming] I've made a type system for J
I also looked through it and became confused. I think I will need to run
the tests or wait for more documentation.
It sounds like the example given solves the problem of detecting
incompatibilities in values or make the values comparable.
In this example it is a list of temperature values which are in different
units. We want to validate the user is supplying data in the right unit or
we want to convert the data supplied to equivalent units.
I can think of some toy examples like
isFreezing =: 32&>:
This will clearly give the user the wrong answer if celsius is passed in
We could define
isFreezingF =: 32&>:
isFreezingC =: 0&>:
Then we would need to know which to call in what circumstance
It would be better to be able to have a function that could try and produce
the right result depending on what the user supplied or produce an error if
not
An explicit way may be to do this:
isFreezing =: 3 : 0
unit=. {: y
temp=. ". }: y
if. unit = 'F' do.
temp <: 32
elseif. unit = 'C' do.
temp <: 0
elseif. do. _1
end.
)
isFreezing every ('32F';'1C';'0C';'5K')
Or we could do something like this
isFreezingF =: 32&>:
isFreezingC =: 0&>:
isFreezingUNK =: _1:
isFreezing2 =: 3 : 0
unit=. {: y
temp=. ". }: y
(isFreezingF`isFreezingC`isFreezingUNK@.('FC' i. unit)) temp
)
isFreezing2 every ('32F';'1C';'0C';'5K')
You can imagine this could get unwieldy if we wanted to add isBoiling or
isHot, isCold or is isWarmerThan ....
In these cases the coercion would be nice to get back to a single base unit.
Now I need to play with your type system to see how it would help with this
problem
On Mon, Jan 26, 2015 at 5:04 PM, Raul Miller <[email protected]> wrote:
> I took a quick look at it.
>
> I do not think lassign is very meaningful. I can think of uses for it,
> but they seem obscure.
>
> Meanwhile, I am also not clear on the difference between 'in' and
> 'of'. (They behave the same on my simple tests, and there's a lot of
> code to wade through, here.
>
> I don't suppose you feel like putting together a ref doc (for example:
> one sentence descriptions on the important words, along with
> representative sample data)? The test scripts look promising, though,
> so maybe I'll discover what I need there...
>
> Thanks,
>
> --
> Raul
>
> On Mon, Jan 26, 2015 at 3:36 PM, 'Pascal Jasmin' via Programming
> <[email protected]> wrote:
> > https://github.com/Pascal-J/type-system-j
> >
> >
> > This is actually the type system I'd like any language to have. Its
> much cleaner than class-based user defined types in that you don't need to
> define casting function into and out of classes.
> >
> > This may be a bit hard for beginners in that to fully use with explicit
> multiline code, the user needs to understand how 3 : 0 can be part of a
> fuller line. But its both powerful to create types, and easy enough for me
> to consume them.
> >
> > Some unique powerful features are compound types, parameterized types,
> and inputwide (record/array vs field) validation (type)s.
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm