How to check type in Racket?










0















I define a function



(define 1-9 (list->set (range 1 10)))


I want to see if 1-9 is really a set. How can I get the type of 1-9?



I tried to google racket check type, but I can't find any useful information.










share|improve this question






















  • generic-set?. As in (generic-set? 1-9) = #true

    – Alex Knauth
    Nov 14 '18 at 2:06











  • So you have to know the type before? What if I have no idea about the type of the output?

    – user8314628
    Nov 14 '18 at 2:07






  • 1





    If you want to see if its a set, use generic-set?. If you want to see if its a list, use list?. If you want to see if its a number, use number?. In Racket types can overlap however, so something could be both a generic-set? and a list?, and that's perfectly fine, just like it's fine for something to be both a number? and an integer?. Any value has the "type" any/c, since (any/c x) is true no matter what x is. 5 has at least three "types" any/c, number?, and integer?. So can you clarify what you actually want, and why predicates like generic-set? aren't enough?

    – Alex Knauth
    Nov 14 '18 at 2:12







  • 1





    Python & Haskell are completely different in this regard; Haskell has a static type system, Python does not. It's probably not a good idea to use the same word ("type") for both of these. I'm relatively confident that you cannot write a function in Haskell that accepts an arbitrary value and returns its type; among other things, I claim this would absolutely destroy parametricity.

    – John Clements
    Nov 14 '18 at 5:46






  • 1





    In Haskell: typeOf :: ∀ a. (Typeable a) => a -> TypeRep, though you're right that Typeable a does not allow an arbitrary type, and because of that parametricity doesn't say much about it. I guess parametricity would say just as much about that as it would about ∀ a. (a -> TypeRep) -> a -> TypeRep

    – Alex Knauth
    Nov 14 '18 at 14:22
















0















I define a function



(define 1-9 (list->set (range 1 10)))


I want to see if 1-9 is really a set. How can I get the type of 1-9?



I tried to google racket check type, but I can't find any useful information.










share|improve this question






















  • generic-set?. As in (generic-set? 1-9) = #true

    – Alex Knauth
    Nov 14 '18 at 2:06











  • So you have to know the type before? What if I have no idea about the type of the output?

    – user8314628
    Nov 14 '18 at 2:07






  • 1





    If you want to see if its a set, use generic-set?. If you want to see if its a list, use list?. If you want to see if its a number, use number?. In Racket types can overlap however, so something could be both a generic-set? and a list?, and that's perfectly fine, just like it's fine for something to be both a number? and an integer?. Any value has the "type" any/c, since (any/c x) is true no matter what x is. 5 has at least three "types" any/c, number?, and integer?. So can you clarify what you actually want, and why predicates like generic-set? aren't enough?

    – Alex Knauth
    Nov 14 '18 at 2:12







  • 1





    Python & Haskell are completely different in this regard; Haskell has a static type system, Python does not. It's probably not a good idea to use the same word ("type") for both of these. I'm relatively confident that you cannot write a function in Haskell that accepts an arbitrary value and returns its type; among other things, I claim this would absolutely destroy parametricity.

    – John Clements
    Nov 14 '18 at 5:46






  • 1





    In Haskell: typeOf :: ∀ a. (Typeable a) => a -> TypeRep, though you're right that Typeable a does not allow an arbitrary type, and because of that parametricity doesn't say much about it. I guess parametricity would say just as much about that as it would about ∀ a. (a -> TypeRep) -> a -> TypeRep

    – Alex Knauth
    Nov 14 '18 at 14:22














0












0








0








I define a function



(define 1-9 (list->set (range 1 10)))


I want to see if 1-9 is really a set. How can I get the type of 1-9?



I tried to google racket check type, but I can't find any useful information.










share|improve this question














I define a function



(define 1-9 (list->set (range 1 10)))


I want to see if 1-9 is really a set. How can I get the type of 1-9?



I tried to google racket check type, but I can't find any useful information.







types racket






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 1:57









user8314628user8314628

56529




56529












  • generic-set?. As in (generic-set? 1-9) = #true

    – Alex Knauth
    Nov 14 '18 at 2:06











  • So you have to know the type before? What if I have no idea about the type of the output?

    – user8314628
    Nov 14 '18 at 2:07






  • 1





    If you want to see if its a set, use generic-set?. If you want to see if its a list, use list?. If you want to see if its a number, use number?. In Racket types can overlap however, so something could be both a generic-set? and a list?, and that's perfectly fine, just like it's fine for something to be both a number? and an integer?. Any value has the "type" any/c, since (any/c x) is true no matter what x is. 5 has at least three "types" any/c, number?, and integer?. So can you clarify what you actually want, and why predicates like generic-set? aren't enough?

    – Alex Knauth
    Nov 14 '18 at 2:12







  • 1





    Python & Haskell are completely different in this regard; Haskell has a static type system, Python does not. It's probably not a good idea to use the same word ("type") for both of these. I'm relatively confident that you cannot write a function in Haskell that accepts an arbitrary value and returns its type; among other things, I claim this would absolutely destroy parametricity.

    – John Clements
    Nov 14 '18 at 5:46






  • 1





    In Haskell: typeOf :: ∀ a. (Typeable a) => a -> TypeRep, though you're right that Typeable a does not allow an arbitrary type, and because of that parametricity doesn't say much about it. I guess parametricity would say just as much about that as it would about ∀ a. (a -> TypeRep) -> a -> TypeRep

    – Alex Knauth
    Nov 14 '18 at 14:22


















  • generic-set?. As in (generic-set? 1-9) = #true

    – Alex Knauth
    Nov 14 '18 at 2:06











  • So you have to know the type before? What if I have no idea about the type of the output?

    – user8314628
    Nov 14 '18 at 2:07






  • 1





    If you want to see if its a set, use generic-set?. If you want to see if its a list, use list?. If you want to see if its a number, use number?. In Racket types can overlap however, so something could be both a generic-set? and a list?, and that's perfectly fine, just like it's fine for something to be both a number? and an integer?. Any value has the "type" any/c, since (any/c x) is true no matter what x is. 5 has at least three "types" any/c, number?, and integer?. So can you clarify what you actually want, and why predicates like generic-set? aren't enough?

    – Alex Knauth
    Nov 14 '18 at 2:12







  • 1





    Python & Haskell are completely different in this regard; Haskell has a static type system, Python does not. It's probably not a good idea to use the same word ("type") for both of these. I'm relatively confident that you cannot write a function in Haskell that accepts an arbitrary value and returns its type; among other things, I claim this would absolutely destroy parametricity.

    – John Clements
    Nov 14 '18 at 5:46






  • 1





    In Haskell: typeOf :: ∀ a. (Typeable a) => a -> TypeRep, though you're right that Typeable a does not allow an arbitrary type, and because of that parametricity doesn't say much about it. I guess parametricity would say just as much about that as it would about ∀ a. (a -> TypeRep) -> a -> TypeRep

    – Alex Knauth
    Nov 14 '18 at 14:22

















generic-set?. As in (generic-set? 1-9) = #true

– Alex Knauth
Nov 14 '18 at 2:06





generic-set?. As in (generic-set? 1-9) = #true

– Alex Knauth
Nov 14 '18 at 2:06













So you have to know the type before? What if I have no idea about the type of the output?

– user8314628
Nov 14 '18 at 2:07





So you have to know the type before? What if I have no idea about the type of the output?

– user8314628
Nov 14 '18 at 2:07




1




1





If you want to see if its a set, use generic-set?. If you want to see if its a list, use list?. If you want to see if its a number, use number?. In Racket types can overlap however, so something could be both a generic-set? and a list?, and that's perfectly fine, just like it's fine for something to be both a number? and an integer?. Any value has the "type" any/c, since (any/c x) is true no matter what x is. 5 has at least three "types" any/c, number?, and integer?. So can you clarify what you actually want, and why predicates like generic-set? aren't enough?

– Alex Knauth
Nov 14 '18 at 2:12






If you want to see if its a set, use generic-set?. If you want to see if its a list, use list?. If you want to see if its a number, use number?. In Racket types can overlap however, so something could be both a generic-set? and a list?, and that's perfectly fine, just like it's fine for something to be both a number? and an integer?. Any value has the "type" any/c, since (any/c x) is true no matter what x is. 5 has at least three "types" any/c, number?, and integer?. So can you clarify what you actually want, and why predicates like generic-set? aren't enough?

– Alex Knauth
Nov 14 '18 at 2:12





1




1





Python & Haskell are completely different in this regard; Haskell has a static type system, Python does not. It's probably not a good idea to use the same word ("type") for both of these. I'm relatively confident that you cannot write a function in Haskell that accepts an arbitrary value and returns its type; among other things, I claim this would absolutely destroy parametricity.

– John Clements
Nov 14 '18 at 5:46





Python & Haskell are completely different in this regard; Haskell has a static type system, Python does not. It's probably not a good idea to use the same word ("type") for both of these. I'm relatively confident that you cannot write a function in Haskell that accepts an arbitrary value and returns its type; among other things, I claim this would absolutely destroy parametricity.

– John Clements
Nov 14 '18 at 5:46




1




1





In Haskell: typeOf :: ∀ a. (Typeable a) => a -> TypeRep, though you're right that Typeable a does not allow an arbitrary type, and because of that parametricity doesn't say much about it. I guess parametricity would say just as much about that as it would about ∀ a. (a -> TypeRep) -> a -> TypeRep

– Alex Knauth
Nov 14 '18 at 14:22






In Haskell: typeOf :: ∀ a. (Typeable a) => a -> TypeRep, though you're right that Typeable a does not allow an arbitrary type, and because of that parametricity doesn't say much about it. I guess parametricity would say just as much about that as it would about ∀ a. (a -> TypeRep) -> a -> TypeRep

– Alex Knauth
Nov 14 '18 at 14:22













1 Answer
1






active

oldest

votes


















2














#lang racket is dynamically typed. Practically speaking, this means you normally do not (should not) care about "The" "Type" of some value.



Instead (as Alex pointed out), you give a value to a "predicate" function like list?. If the predicate returns true, then you may go ahead and do list-y things with the value -- give the value to functions that expect list.



This is much more useful and reliable than having something like (typeof value) that returns magic symbols like List. After all, what you care about is what you can do with the value. A predicate tells you that. And a predicate allows for values that can be used in more than one way (e.g. as a list and as a set, both).




p.s. This is similar to why version numbers (like Semantic Versioning) are so silly. Given some installed library, what you actually care about is, does it provide certain functions and behavior. You want to ask the actual installed library, do you provide function X -- not use some magic number and outside information to guess.




p.p.s. What if you want to serialize values (write and read them to a file)? You do need to choose a way to represent each value. In Racket one approach is to use the printed representation of primitive values, and something like prefab structs for others -- then use write and read. There is also racket/serialize. In any case, serializing values is a relatively rare thing to do.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292108%2fhow-to-check-type-in-racket%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    #lang racket is dynamically typed. Practically speaking, this means you normally do not (should not) care about "The" "Type" of some value.



    Instead (as Alex pointed out), you give a value to a "predicate" function like list?. If the predicate returns true, then you may go ahead and do list-y things with the value -- give the value to functions that expect list.



    This is much more useful and reliable than having something like (typeof value) that returns magic symbols like List. After all, what you care about is what you can do with the value. A predicate tells you that. And a predicate allows for values that can be used in more than one way (e.g. as a list and as a set, both).




    p.s. This is similar to why version numbers (like Semantic Versioning) are so silly. Given some installed library, what you actually care about is, does it provide certain functions and behavior. You want to ask the actual installed library, do you provide function X -- not use some magic number and outside information to guess.




    p.p.s. What if you want to serialize values (write and read them to a file)? You do need to choose a way to represent each value. In Racket one approach is to use the printed representation of primitive values, and something like prefab structs for others -- then use write and read. There is also racket/serialize. In any case, serializing values is a relatively rare thing to do.






    share|improve this answer



























      2














      #lang racket is dynamically typed. Practically speaking, this means you normally do not (should not) care about "The" "Type" of some value.



      Instead (as Alex pointed out), you give a value to a "predicate" function like list?. If the predicate returns true, then you may go ahead and do list-y things with the value -- give the value to functions that expect list.



      This is much more useful and reliable than having something like (typeof value) that returns magic symbols like List. After all, what you care about is what you can do with the value. A predicate tells you that. And a predicate allows for values that can be used in more than one way (e.g. as a list and as a set, both).




      p.s. This is similar to why version numbers (like Semantic Versioning) are so silly. Given some installed library, what you actually care about is, does it provide certain functions and behavior. You want to ask the actual installed library, do you provide function X -- not use some magic number and outside information to guess.




      p.p.s. What if you want to serialize values (write and read them to a file)? You do need to choose a way to represent each value. In Racket one approach is to use the printed representation of primitive values, and something like prefab structs for others -- then use write and read. There is also racket/serialize. In any case, serializing values is a relatively rare thing to do.






      share|improve this answer

























        2












        2








        2







        #lang racket is dynamically typed. Practically speaking, this means you normally do not (should not) care about "The" "Type" of some value.



        Instead (as Alex pointed out), you give a value to a "predicate" function like list?. If the predicate returns true, then you may go ahead and do list-y things with the value -- give the value to functions that expect list.



        This is much more useful and reliable than having something like (typeof value) that returns magic symbols like List. After all, what you care about is what you can do with the value. A predicate tells you that. And a predicate allows for values that can be used in more than one way (e.g. as a list and as a set, both).




        p.s. This is similar to why version numbers (like Semantic Versioning) are so silly. Given some installed library, what you actually care about is, does it provide certain functions and behavior. You want to ask the actual installed library, do you provide function X -- not use some magic number and outside information to guess.




        p.p.s. What if you want to serialize values (write and read them to a file)? You do need to choose a way to represent each value. In Racket one approach is to use the printed representation of primitive values, and something like prefab structs for others -- then use write and read. There is also racket/serialize. In any case, serializing values is a relatively rare thing to do.






        share|improve this answer













        #lang racket is dynamically typed. Practically speaking, this means you normally do not (should not) care about "The" "Type" of some value.



        Instead (as Alex pointed out), you give a value to a "predicate" function like list?. If the predicate returns true, then you may go ahead and do list-y things with the value -- give the value to functions that expect list.



        This is much more useful and reliable than having something like (typeof value) that returns magic symbols like List. After all, what you care about is what you can do with the value. A predicate tells you that. And a predicate allows for values that can be used in more than one way (e.g. as a list and as a set, both).




        p.s. This is similar to why version numbers (like Semantic Versioning) are so silly. Given some installed library, what you actually care about is, does it provide certain functions and behavior. You want to ask the actual installed library, do you provide function X -- not use some magic number and outside information to guess.




        p.p.s. What if you want to serialize values (write and read them to a file)? You do need to choose a way to represent each value. In Racket one approach is to use the printed representation of primitive values, and something like prefab structs for others -- then use write and read. There is also racket/serialize. In any case, serializing values is a relatively rare thing to do.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 16:00









        Greg HendershottGreg Hendershott

        10.5k42343




        10.5k42343



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292108%2fhow-to-check-type-in-racket%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands