Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined at the type level

Often when I'm playing with Haskell code, I stub things out with a type annotation and undefined.

foo :: String -> Int
foo = undefined

Is there a type-level "undefined" that I could use in a similar way?

(Ideally, in conjunction with a kind annotation)

type Foo :: * -> *
type Foo = Undefined

Further thought on the same thread: is there a way for me to stub out typeclass instances for types created this way? An even easier way than the following theoretical way?

instance Monad Foo where
  return = undefined
  (>>=) = undefined
like image 828
Dan Burton Avatar asked Jan 27 '12 16:01

Dan Burton


People also ask

Why undefined is a data type?

A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned .

Is undefined a data type?

The undefined datatype, whose value is undefined is used to denote an absence of a meaningful value. A variable in JavaScript that is without any value has a value of undefined. The datatype of a variable that holds an undefined value is also 'undefined'.

Is undefined equal to undefined?

undefined does not equal undefined.

How do you make a variable undefined in typescript?

You can assign a avariable with undefined. testVar = undefined; //typeof(testVar) will be equal to undefined. Save this answer.


2 Answers

You can use EmptyDataDecls to stub out a type, and with KindSignatures you can give it a kind:

{-# LANGUAGE EmptyDataDecls, KindSignatures #-}

data Foo :: * -> *

You can also stub out the Monad instance without warnings with this option to GHC.

{-# OPTIONS_GHC -fno-warn-missing-methods #-}

instance Monad Foo

And then you don't need to leave any implementation for return and >>=.

like image 195
danr Avatar answered Oct 24 '22 07:10

danr


This question was asked and answered a long time ago; best practices have evolved since.

These days, instead of undefined, for stubbing out code you should be using typed holes, and their type-level analogue, partial type signatures.

like image 3
Dan Burton Avatar answered Oct 24 '22 09:10

Dan Burton